SlideShare a Scribd company logo
Welcome
gdscpython.pdf
gdscpython.pdf
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.
gdscpython.pdf
gdscpython.pdf
gdscpython.pdf
gdscpython.pdf
gdscpython.pdf
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
gdscpython.pdf
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])
gdscpython.pdf
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 (20)

PPTX
Python basics
Luis Goldster
 
PPTX
Python basics
Tony Nguyen
 
PPTX
Python basics
Fraboni Ec
 
PPTX
Python basics
Harry Potter
 
PPTX
Python basics
Young Alista
 
PPTX
Python basics
James Wong
 
PPTX
1. control structures in the python.pptx
DURAIMURUGANM2
 
PDF
Introduction to python
mckennadglyn
 
PDF
Python tutorial
Dominik KAszubowski
 
PDF
Python Tutorial
AkramWaseem
 
PPTX
PYTHON PROGRAMMING.pptx
swarna627082
 
PDF
Introduction To Programming with Python
Sushant Mane
 
PPTX
Programming with python
sarogarage
 
PDF
pyton Notes1
Amba Research
 
PPTX
lecture 2.pptx
Anonymous9etQKwW
 
PDF
Python intro
Abhinav Upadhyay
 
PDF
Python Programming Module 3 (2).pdf
Thanmayee S
 
PPTX
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
PPTX
Python Basics
primeteacher32
 
PPTX
Introduction to python programming 1
Giovanni Della Lunga
 
Python basics
Luis Goldster
 
Python basics
Tony Nguyen
 
Python basics
Fraboni Ec
 
Python basics
Harry Potter
 
Python basics
Young Alista
 
Python basics
James Wong
 
1. control structures in the python.pptx
DURAIMURUGANM2
 
Introduction to python
mckennadglyn
 
Python tutorial
Dominik KAszubowski
 
Python Tutorial
AkramWaseem
 
PYTHON PROGRAMMING.pptx
swarna627082
 
Introduction To Programming with Python
Sushant Mane
 
Programming with python
sarogarage
 
pyton Notes1
Amba Research
 
lecture 2.pptx
Anonymous9etQKwW
 
Python intro
Abhinav Upadhyay
 
Python Programming Module 3 (2).pdf
Thanmayee S
 
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
Python Basics
primeteacher32
 
Introduction to python programming 1
Giovanni Della Lunga
 

Recently uploaded (20)

PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Introduction to Indian Writing in English
Trushali Dodiya
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Horarios de distribución de agua en julio
pegazohn1978
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Difference between write and update in odoo 18
Celine George
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
Introduction presentation of the patentbutler tool
MIPLM
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Ad

gdscpython.pdf

  • 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.
  • 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.
  • 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])
  • 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/