SlideShare a Scribd company logo
1 of 27
Download to read offline
Welcome
Comments
Comments are useful information that the developers
provide to make the reader understand the source code. It
explains the logic or a part of it used in the code. There are
two types of comment in Python:
● Single line comments: Python single line comment starts
with hashtag symbol with no white spaces.
Multi-line string as comment: Python multi-line comment
is a piece of text enclosed in a delimiter (“””) on each end
of the comment.
Headline
Subtitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum gravida
placerat dictum. Sed sagittis accumsan dolor ut malesuada. Duis sit amet
placerat quam. Donec eget eros egestas nunc venenatis suscipit at at felis. Duis
sit amet placerat quam.
● Deleting/Updating from a String –
● In Python, Updation or deletion of characters from a String is not allowed
because Strings are immutable. Only new strings can be reassigned to the
same name.
Mutability and Immutability
Basics of Input/Output
Input() and print()
name = input('What is your name?n') # n ---> newline ---> It causes a line
break
print(name)
When input() function executes program flow will be stopped until the user has given input.
The text or message displayed on the output screen to ask a user to enter an input value is optional
i.e. the prompt, which will be printed on the screen is optional.
Whatever you enter as input, the input function converts it into a string. if you enter an integer value
still input() function converts it into a string. You need to explicitly convert it into an integer in your
code using typecasting.
# Program to check input
# type in Python
num = input ("Enter number :")
print(num)
name1 = input("Enter name : ")
print(name1)
# Printing type of input value
print ("type of number", type(num))
print ("type of name", type(name1))
It will show the type of input as str
num = int(input("Enter a number: "))
print(num, " ", type(num))
floatNum = float(input("Enter a decimal number: "))
print(floatNum, " ", type(floatNum))
what will it show about the type of input?
# Python Program for
# Creation of String
# String with single quotes
print('Welcome to the GDSC HIT')
# String with double quotes
print("I'm a Abhishek Pandey")
# String with triple quotes
print(‘ ‘ ‘ I'm a 3rd year student and I live in a world of “Aliens“ ‘ ‘ ‘ )
# Python Program to Access
# characters of String
String1 = “Python“
# Printing First character
print(String1[0])
# Printing Last character
print(String1[-1])
In computer programming, we use the if statement to run a block code only
when a certain condition is met.
Indentation in Python
Indentation is a very important concept of Python because
without properly indenting the Python code, you will end
up seeing IndentationError and the code will not get
compiled.
Python indentation refers to adding white space before a
statement to a particular block of code. In another word,
all the statements with the same space to the right,
belong to the same code block
If Elif Else
Let’s Create a Guessing
game:
Let’s try to implement the following condition
For example, assigning grades (A, B, C) based on marks obtained by a student.
1.if the percentage is above 90, assign grade A
2.if the percentage is above 75, assign grade B
3.if the percentage is above 65, assign grade C
Colors, Charts, and Icons
While Loop in Python:-
In python, a while loop is used to execute a block of statements repeatedly until a given condition is satisfied.
And when the condition becomes false, the line immediately after the loop in the program is executed.
# Python program to illustrate while loop
count = 0
while (count < 3):
count = count + 1
print("Hello!")
Examples of While Loop with else statement
# Python program to illustrate
# combining else with while
count = 0
while (count < 3):
count = count + 1
print("Hello")
else:
print("In Else Block")
Colors, Charts, and Icons
For Loop in Python:-
For loops are used for sequential traversal. For example: traversing a list or string or array etc. In Python, there
is “for in” loop which is similar to for each loop in other languages. Let us learn how to use for in loop for
sequential traversals.
# Python program to illustrate
# Iterating over range 0 to n-1
n = 4
for i in range(0, n):
print(i)
output?
Decrementing With range():
for i in range(10, -6, -2):
print(i)
This will start at 10 and count down by 2 until you reach -6, or rather -4 because you don’t include -6.
This will start at 10 and count down by 2 until you reach -6, or rather -4 because you don’t include -6.
Colors, Charts, and Icons
Nested Loops:-
Python programming language allows to use one loop inside another loop.
We will use nested loop to print right angle triangle star pattern.
Let’s see how this work:
for i in range(1, 5):
for j in range(i):
print(i, end=' ')
print()
what is end here?
# ends the output with a space
print("Welcome to", end = ' ')
print("GeeksforGeeks", end= ' ')
Print statement automatically print a new line after the prompt inside it.
To prevent creating new line and to continue with same line we use end=“ ”
Star Patterns:-
Example:
for i in range(1, 9):
for j in range(i):
print(“*”, end=' ')
print()
Python Print Star Patterns 14 Programs
https://easycodebook.com/2021/05/python-print-star-pattern-shapes-programs/
Thank You 

More Related Content

Similar to gdscpython.pdf

Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| FundamentalsMohd Sajjad
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdfsimenehanmut
 
Notes1
Notes1Notes1
Notes1hccit
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)ExcellenceAcadmy
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)ExcellenceAcadmy
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computingGo Asgard
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL Rishabh-Rawat
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine LearningYounesCharfaoui
 
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfCode In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfaishwaryaequipment
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
 

Similar to gdscpython.pdf (20)

Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
MODULE. .pptx
MODULE.                              .pptxMODULE.                              .pptx
MODULE. .pptx
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
Notes1
Notes1Notes1
Notes1
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
python
pythonpython
python
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
 
UNIT 4 python.pptx
UNIT 4 python.pptxUNIT 4 python.pptx
UNIT 4 python.pptx
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine Learning
 
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfCode In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
 
Python basics
Python basicsPython basics
Python basics
 
chapter_5_ppt_em_220247.pptx
chapter_5_ppt_em_220247.pptxchapter_5_ppt_em_220247.pptx
chapter_5_ppt_em_220247.pptx
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

gdscpython.pdf

  • 2.
  • 3.
  • 4. Comments Comments are useful information that the developers provide to make the reader understand the source code. It explains the logic or a part of it used in the code. There are two types of comment in Python: ● Single line comments: Python single line comment starts with hashtag symbol with no white spaces. Multi-line string as comment: Python multi-line comment is a piece of text enclosed in a delimiter (“””) on each end of the comment.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Headline Subtitle Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum gravida placerat dictum. Sed sagittis accumsan dolor ut malesuada. Duis sit amet placerat quam. Donec eget eros egestas nunc venenatis suscipit at at felis. Duis sit amet placerat quam.
  • 11. ● Deleting/Updating from a String – ● In Python, Updation or deletion of characters from a String is not allowed because Strings are immutable. Only new strings can be reassigned to the same name.
  • 13.
  • 14. Basics of Input/Output Input() and print() name = input('What is your name?n') # n ---> newline ---> It causes a line break print(name) When input() function executes program flow will be stopped until the user has given input. The text or message displayed on the output screen to ask a user to enter an input value is optional i.e. the prompt, which will be printed on the screen is optional. Whatever you enter as input, the input function converts it into a string. if you enter an integer value still input() function converts it into a string. You need to explicitly convert it into an integer in your code using typecasting.
  • 15. # Program to check input # type in Python num = input ("Enter number :") print(num) name1 = input("Enter name : ") print(name1) # Printing type of input value print ("type of number", type(num)) print ("type of name", type(name1)) It will show the type of input as str
  • 16. num = int(input("Enter a number: ")) print(num, " ", type(num)) floatNum = float(input("Enter a decimal number: ")) print(floatNum, " ", type(floatNum)) what will it show about the type of input?
  • 17. # Python Program for # Creation of String # String with single quotes print('Welcome to the GDSC HIT') # String with double quotes print("I'm a Abhishek Pandey") # String with triple quotes print(‘ ‘ ‘ I'm a 3rd year student and I live in a world of “Aliens“ ‘ ‘ ‘ )
  • 18. # Python Program to Access # characters of String String1 = “Python“ # Printing First character print(String1[0]) # Printing Last character print(String1[-1])
  • 19.
  • 20. In computer programming, we use the if statement to run a block code only when a certain condition is met. Indentation in Python Indentation is a very important concept of Python because without properly indenting the Python code, you will end up seeing IndentationError and the code will not get compiled. Python indentation refers to adding white space before a statement to a particular block of code. In another word, all the statements with the same space to the right, belong to the same code block If Elif Else
  • 21. Let’s Create a Guessing game:
  • 22. Let’s try to implement the following condition For example, assigning grades (A, B, C) based on marks obtained by a student. 1.if the percentage is above 90, assign grade A 2.if the percentage is above 75, assign grade B 3.if the percentage is above 65, assign grade C
  • 23. Colors, Charts, and Icons While Loop in Python:- In python, a while loop is used to execute a block of statements repeatedly until a given condition is satisfied. And when the condition becomes false, the line immediately after the loop in the program is executed. # Python program to illustrate while loop count = 0 while (count < 3): count = count + 1 print("Hello!") Examples of While Loop with else statement # Python program to illustrate # combining else with while count = 0 while (count < 3): count = count + 1 print("Hello") else: print("In Else Block")
  • 24. Colors, Charts, and Icons For Loop in Python:- For loops are used for sequential traversal. For example: traversing a list or string or array etc. In Python, there is “for in” loop which is similar to for each loop in other languages. Let us learn how to use for in loop for sequential traversals. # Python program to illustrate # Iterating over range 0 to n-1 n = 4 for i in range(0, n): print(i) output? Decrementing With range(): for i in range(10, -6, -2): print(i) This will start at 10 and count down by 2 until you reach -6, or rather -4 because you don’t include -6. This will start at 10 and count down by 2 until you reach -6, or rather -4 because you don’t include -6.
  • 25. Colors, Charts, and Icons Nested Loops:- Python programming language allows to use one loop inside another loop. We will use nested loop to print right angle triangle star pattern. Let’s see how this work: for i in range(1, 5): for j in range(i): print(i, end=' ') print() what is end here? # ends the output with a space print("Welcome to", end = ' ') print("GeeksforGeeks", end= ' ') Print statement automatically print a new line after the prompt inside it. To prevent creating new line and to continue with same line we use end=“ ”
  • 26. Star Patterns:- Example: for i in range(1, 9): for j in range(i): print(“*”, end=' ') print() Python Print Star Patterns 14 Programs https://easycodebook.com/2021/05/python-print-star-pattern-shapes-programs/