SlideShare a Scribd company logo
Programming
with
Python
Content to be discuss …
• Variables
• Operands and Expressions
• Conditional Statements
Variables
• Variables are the names given to data that we need to store and
manipulate in our program.
• For example ,to store the age of the user ,we can write a variable
age and it is defined as below.
age = 0 or age = 50
After we define age ,the program will allocate some memory to
store this data.
• Every time we declare a variable ,some initial value must be given
to it.
• We can also define multiple variables at a time.
For ex: age, name=30,’Peter’
This is same as age=30
name=‘Peter’
• The user name can contain any letters (lower case or upper case)
numbers or underscores(-) but the first character shouldn’t be a
number
• For Ex: userName,user_Name,user_Name2 etc.. Are valid.
• But… 2user_name ,2userName ..are not valid
• Variable names are case sensitive .username and userNAME are
not same.
• Normally two conventions are used in Python to denote
variables. Camel case notation or use underscores .
• Camel case is the practice of writing the compound words with
mixed casing. For ex:”thisIsAvariableName”
• Another is to use underscores (-).
Some precautions
• This separates the words.For example:
“user_Name_variable”
• In the above example age=30,the ‘=‘ sign is
known as Assignment Sign
• So the statements x=y and y=x have different
meanings in programming.
Basic Operators
• Python accepts all the basic operators like + (addition),
(subtraction),*(multiplication), / (division), //(floor division),
%(modulus) and **(exponent).
• For example : if x= 7,y=2
addition: x+y=9
subtraction:x-y=5
Multiplication:x*y=14
Division: x/y=3.5
• Floor division: x // y=3(rounds off the answer to the nearest
whole number)
• Modulus: x%y= 1(Gives the remainder when 7 is divided by 2
• Exponent : x**y=49(7 to the power of 2)
Additional assignment Operators
• +=: x+= 2 is same as equal to x=x+2
• Similarly for subtraction x-=2 is
same as x=x-2
Data Types
• Integers are numbers with no decimal parts like 2 , -5 , 27, 0 ,
1375 etc..
• Float refers to a number that has decimal parts. Ex: 1.2467 ;
-0.7865 ; 125.876
• userHeight = 12.53 userWeight = 65.872
• String: String refers to text. Strings are defined within single quotes.
• For Ex: Variable Name = ‘initialvalue’
• VariableName=“initial value”
• userName=‘peter’ ,userSpouseName=“Mary” userAge =“35” here
“35” is a string
• Multiple substrings can be combined by using the concatenate
sign(+)
• Ex:”Peter”+ “Lee” is equivalent to the string “PeterLee”
Type Casting
• Type casting helps to convert from one data type to another .i.e
from integer to a string or vice versa.
• There are three built in functions in Python int(); str() ;
float()
• To change a float to an integer type int(7.3256).
The output is 7
• To change a string into integer int(“4”).The output is 4
• Ex: int(“RAM”) ----- returns syntax error
• int(“3.7654”) -------returns syntax error
• The str() function converts an integer or a float to a string.
• Ex: str(82.1) The output is “82.1”
• Ex: str(757) The output is “757”
• Ex: str(Ram) The output is “Ram”
Conditional Statement
• if statement
• if… else statement
• Nested if statement
Python uses indentation as its
method of grouping statements
Indentation
• Indentation refers to the spaces at the
beginning of a code line.
• Python uses indentation to indicate a block of
code.
Example:
if 7 > 3:
print(“Seven is greater than three *** ")
Python generates an error without indentation
in a block of code.
Assignment Section
Write a python program to :
• find maximum between two numbers
• find minimum between three numbers.
• check whether a number is negative, positive or zero.
• whether a number is divisible by 5 and 11 or not.
• check whether a number is even or odd.
• check whether a year is leap year or not.
• input week number and print week day
• input month number and print number of days in that
month.
• count total number of notes in given amount
Ad

Recommended

Python numbers
Python numbers
Smt. Indira Gandhi College of Engineering, Navi Mumbai, Mumbai
 
Python Data-Types
Python Data-Types
Akhil Kaushik
 
Session 4
Session 4
Shailendra Mathur
 
An Introduction : Python
An Introduction : Python
Raghu Kumar
 
Arrays in c language
Arrays in c language
tanmaymodi4
 
Pointers in c
Pointers in c
CHANDAN KUMAR
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
Arrays in C++
Arrays in C++
Ilio Catallo
 
Programming construction tools
Programming construction tools
sunilchute1
 
Loops in Python
Loops in Python
Arockia Abins
 
Python : Data Types
Python : Data Types
Emertxe Information Technologies Pvt Ltd
 
Unit v
Unit v
SHIKHA GAUTAM
 
Python ppt
Python ppt
Anush verma
 
Multidimensional arrays in C++
Multidimensional arrays in C++
Ilio Catallo
 
Iteration
Iteration
Pooja B S
 
Arrays in c
Arrays in c
CHANDAN KUMAR
 
C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
C Pointers
C Pointers
omukhtar
 
Unit iii
Unit iii
SHIKHA GAUTAM
 
Pointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
C intro
C intro
SHIKHA GAUTAM
 
Python advance
Python advance
Deepak Chandella
 
Pointers C programming
Pointers C programming
Appili Vamsi Krishna
 
Pointers in c++
Pointers in c++
sai tarlekar
 
Python unit 2 M.sc cs
Python unit 2 M.sc cs
KALAISELVI P
 
Arrays-Computer programming
Arrays-Computer programming
nmahi96
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Review old Pygame made using python programming.pptx
Review old Pygame made using python programming.pptx
ithepacer
 
Introduction to Python for Plone developers
Introduction to Python for Plone developers
Jim Roepcke
 
Python Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 

More Related Content

What's hot (18)

Programming construction tools
Programming construction tools
sunilchute1
 
Loops in Python
Loops in Python
Arockia Abins
 
Python : Data Types
Python : Data Types
Emertxe Information Technologies Pvt Ltd
 
Unit v
Unit v
SHIKHA GAUTAM
 
Python ppt
Python ppt
Anush verma
 
Multidimensional arrays in C++
Multidimensional arrays in C++
Ilio Catallo
 
Iteration
Iteration
Pooja B S
 
Arrays in c
Arrays in c
CHANDAN KUMAR
 
C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
C Pointers
C Pointers
omukhtar
 
Unit iii
Unit iii
SHIKHA GAUTAM
 
Pointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
C intro
C intro
SHIKHA GAUTAM
 
Python advance
Python advance
Deepak Chandella
 
Pointers C programming
Pointers C programming
Appili Vamsi Krishna
 
Pointers in c++
Pointers in c++
sai tarlekar
 
Python unit 2 M.sc cs
Python unit 2 M.sc cs
KALAISELVI P
 
Arrays-Computer programming
Arrays-Computer programming
nmahi96
 

Similar to Basics of Python Programming (20)

Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Review old Pygame made using python programming.pptx
Review old Pygame made using python programming.pptx
ithepacer
 
Introduction to Python for Plone developers
Introduction to Python for Plone developers
Jim Roepcke
 
Python Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
03-Variables, Expressions and Statements (1).pdf
03-Variables, Expressions and Statements (1).pdf
MirHazarKhan1
 
Pythonlearn-02-Expressions123AdvanceLevel.pptx
Pythonlearn-02-Expressions123AdvanceLevel.pptx
AninditaSarkarNaha
 
Review 2Pygame made using python programming
Review 2Pygame made using python programming
ithepacer
 
IoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptx
afsheenfaiq2
 
Chapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
c-programming
c-programming
Zulhazmi Harith
 
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
sakchaisengsui
 
lecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
rohithzach
 
Python basics
Python basics
Hoang Nguyen
 
Python basics
Python basics
Harry Potter
 
Python basics
Python basics
Fraboni Ec
 
Python basics
Python basics
James Wong
 
Python basics
Python basics
Tony Nguyen
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Review old Pygame made using python programming.pptx
Review old Pygame made using python programming.pptx
ithepacer
 
Introduction to Python for Plone developers
Introduction to Python for Plone developers
Jim Roepcke
 
Python Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
03-Variables, Expressions and Statements (1).pdf
03-Variables, Expressions and Statements (1).pdf
MirHazarKhan1
 
Pythonlearn-02-Expressions123AdvanceLevel.pptx
Pythonlearn-02-Expressions123AdvanceLevel.pptx
AninditaSarkarNaha
 
Review 2Pygame made using python programming
Review 2Pygame made using python programming
ithepacer
 
IoT-Week1-Day1-Lab.pptx
IoT-Week1-Day1-Lab.pptx
afsheenfaiq2
 
Chapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
sakchaisengsui
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
rohithzach
 
Ad

Recently uploaded (20)

GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
RAKESH SAJJAN
 
Nutrition Assessment and Nutrition Education – Unit 4 | B.Sc Nursing 5th Seme...
Nutrition Assessment and Nutrition Education – Unit 4 | B.Sc Nursing 5th Seme...
RAKESH SAJJAN
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
parmarjuli1412
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
Community Health Nursing Approaches, Concepts, Roles & Responsibilities – Uni...
RAKESH SAJJAN
 
Nutrition Assessment and Nutrition Education – Unit 4 | B.Sc Nursing 5th Seme...
Nutrition Assessment and Nutrition Education – Unit 4 | B.Sc Nursing 5th Seme...
RAKESH SAJJAN
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
parmarjuli1412
 
Ad

Basics of Python Programming

  • 2. Content to be discuss … • Variables • Operands and Expressions • Conditional Statements
  • 3. Variables • Variables are the names given to data that we need to store and manipulate in our program. • For example ,to store the age of the user ,we can write a variable age and it is defined as below. age = 0 or age = 50 After we define age ,the program will allocate some memory to store this data. • Every time we declare a variable ,some initial value must be given to it. • We can also define multiple variables at a time. For ex: age, name=30,’Peter’ This is same as age=30 name=‘Peter’
  • 4. • The user name can contain any letters (lower case or upper case) numbers or underscores(-) but the first character shouldn’t be a number • For Ex: userName,user_Name,user_Name2 etc.. Are valid. • But… 2user_name ,2userName ..are not valid • Variable names are case sensitive .username and userNAME are not same. • Normally two conventions are used in Python to denote variables. Camel case notation or use underscores . • Camel case is the practice of writing the compound words with mixed casing. For ex:”thisIsAvariableName” • Another is to use underscores (-). Some precautions
  • 5. • This separates the words.For example: “user_Name_variable” • In the above example age=30,the ‘=‘ sign is known as Assignment Sign • So the statements x=y and y=x have different meanings in programming.
  • 6. Basic Operators • Python accepts all the basic operators like + (addition), (subtraction),*(multiplication), / (division), //(floor division), %(modulus) and **(exponent). • For example : if x= 7,y=2 addition: x+y=9 subtraction:x-y=5 Multiplication:x*y=14 Division: x/y=3.5 • Floor division: x // y=3(rounds off the answer to the nearest whole number) • Modulus: x%y= 1(Gives the remainder when 7 is divided by 2 • Exponent : x**y=49(7 to the power of 2)
  • 7. Additional assignment Operators • +=: x+= 2 is same as equal to x=x+2 • Similarly for subtraction x-=2 is same as x=x-2
  • 8. Data Types • Integers are numbers with no decimal parts like 2 , -5 , 27, 0 , 1375 etc.. • Float refers to a number that has decimal parts. Ex: 1.2467 ; -0.7865 ; 125.876 • userHeight = 12.53 userWeight = 65.872 • String: String refers to text. Strings are defined within single quotes. • For Ex: Variable Name = ‘initialvalue’ • VariableName=“initial value” • userName=‘peter’ ,userSpouseName=“Mary” userAge =“35” here “35” is a string • Multiple substrings can be combined by using the concatenate sign(+) • Ex:”Peter”+ “Lee” is equivalent to the string “PeterLee”
  • 9. Type Casting • Type casting helps to convert from one data type to another .i.e from integer to a string or vice versa. • There are three built in functions in Python int(); str() ; float() • To change a float to an integer type int(7.3256). The output is 7 • To change a string into integer int(“4”).The output is 4 • Ex: int(“RAM”) ----- returns syntax error • int(“3.7654”) -------returns syntax error • The str() function converts an integer or a float to a string. • Ex: str(82.1) The output is “82.1” • Ex: str(757) The output is “757” • Ex: str(Ram) The output is “Ram”
  • 10. Conditional Statement • if statement • if… else statement • Nested if statement Python uses indentation as its method of grouping statements
  • 11. Indentation • Indentation refers to the spaces at the beginning of a code line. • Python uses indentation to indicate a block of code. Example: if 7 > 3: print(“Seven is greater than three *** ") Python generates an error without indentation in a block of code.
  • 12. Assignment Section Write a python program to : • find maximum between two numbers • find minimum between three numbers. • check whether a number is negative, positive or zero. • whether a number is divisible by 5 and 11 or not. • check whether a number is even or odd. • check whether a year is leap year or not. • input week number and print week day • input month number and print number of days in that month. • count total number of notes in given amount