SlideShare a Scribd company logo
Basics of
Python
PGDCA
Conditional Statements
 There comes situations in real life when we need to
do some specific task and based on some specific
conditions and, we decide what should we do next.
Similarly there comes a situation in programming
where a specific task is to be performed if a specific
condition is True. In such cases, conditional
statements can be used.
 The following are the conditional statements
provided by Python.
 if
 If else
 Nested if
If Statement
 If the simple code of block is to be performed
if the condition holds true then the if statement is
used. Here the condition mentioned holds true
then the code of the block runs otherwise not.
 Syntax:
 if condition:
 # Statements to execute if
 # condition is true
If else Statement
 In conditional if Statement the additional
block of code is merged as else statement which
is performed when if condition is false.
 Syntax:
 if (condition):
 # Executes this block if
 # condition is true
 else:
 # Executes this block if
 # condition is false
Nested if Statement
 if statement can also be checked inside other if
statement. This conditional statement is called a
nested if statement. This means that inner if
condition will be checked only if outer if condition is
true and by this, we can see multiple conditions to
be satisfied.
 Syntax:
 if (condition1):
 # Executes when condition1 is true
 if (condition2):
 # Executes when condition2 is true
 # if Block is end here
 # if Block is end here
Loops
 Python programming language provides the
following types of loops to handle looping
requirements. Python provides three ways for
executing the loops. While all the ways provide
similar basic functionality, they differ in their syntax
and condition-checking time.
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.
 Syntax:
 while expression: statement(s)
For Loop
 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.

 Syntax:
 for iterator_var in sequence: statements(s)
Loop Control Statements
 Loop control statements change execution from
their normal sequence. When execution leaves a
scope, all automatic objects that were created in
that scope are destroyed. Python supports the
following control statements.
 Continue Statement
 the continue statement
 in Python returns the
 control to the beginning
 of the loop.
Break Statement
 The break statement in Python brings control
out of the loop.
Functions
 A function is a block of code which only runs
when it is called.
 You can pass data, known as parameters, into a
function.
 A function can return data as a result.
Invoking Built In Functions
 Python has various functions which are readily
available. These functions are termed built in functions. On
this reference page, you will be able to see all the built-in
functions available in Python:
 Python abs()
 It returns the absolute and exact value of a given number
 Python all()
 It returns true when all the elements in iterable are true
 Python chr()
 It returns a Character from an Integer
 Python classmethod()
 It returns the class method for the provided function
random() Function in
Python
 random(), simply speaking, is an inbuilt function of
the random module in Python3 and it helps in the
derivation of the python random list. Furthermore,
the random module in Python provides access to
some useful functions and one of them is able to
facilitate the generation of random floating
numbers, which is random(). Also, its syntax is
random. random() python.
 Syntax: random.random()
 Parameters: Any parameter is not accepted by
this method.
 Returns: Random floating number between 0
and 1 is returned by this method.
random() Function in
Python
randint() Function in
Python
 randint() refers to an inbuilt function belonging to
the random module in Python3. Furthermore,
access is provided by random module provides
access to some beneficial functions.
Moreover, one of the functions is to generate
random numbers, which is randint().
 Syntax : randint(start, end)
 Parameters : (start, end) : Both of them have to
be integer-type values.
 Returns : A random integer in the range [start,
end] consisting of the endpoints.

randint() Function in
Python
Errors and Exceptions :
 ValueError: Returns a ValueError when floating-
point values are passed as parameters.
 TypeError: TypeError is returned when anything
other than numeric values is passed as
parameters.

More Related Content

PDF
E-Notes_3721_Content_Document_20250107032537PM.pdf
PPTX
Types of Statements in Python Programming Language
PDF
PYTHON FULL TUTORIAL WITH PROGRAMMS
PPTX
RaspberryPi & Python Workshop Day - 02.pptx
PDF
if else python.pdf
PPTX
The Awesome Python Class Part-3
DOCX
Python Interview Questions For Experienced
PPTX
Chapter - 3.pptx
E-Notes_3721_Content_Document_20250107032537PM.pdf
Types of Statements in Python Programming Language
PYTHON FULL TUTORIAL WITH PROGRAMMS
RaspberryPi & Python Workshop Day - 02.pptx
if else python.pdf
The Awesome Python Class Part-3
Python Interview Questions For Experienced
Chapter - 3.pptx

Similar to ppt python notes list tuple data types ope (20)

PDF
ch2 Python flow control.pdf
PPTX
Python Session - 4
PPT
Python session3
PPT
Control structures pyhton
PPTX
Control_Statements_in_Python.pptx
PPTX
Introduction to Python for Data Science and Machine Learning
PPTX
Week 2.pptx
PPTX
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
PDF
GE3151 UNIT II Study material .pdf
PPTX
Introduction To Programming with Python Lecture 2
PDF
Unit 1- Part-2-Control and Loop Statements.pdf
PPTX
Introduction to Python Part-1
PDF
2-functions.pptx_20240619_085610_0000.pdf
PDF
Python Flow Control
PPTX
Python
DOCX
Python interview questions and answers
PPTX
Unit - 2 CAP.pptx
PPS
Programming in Arduino (Part 2)
PDF
Python interview questions and answers
PDF
Anton Kasyanov, Introduction to Python, Lecture2
ch2 Python flow control.pdf
Python Session - 4
Python session3
Control structures pyhton
Control_Statements_in_Python.pptx
Introduction to Python for Data Science and Machine Learning
Week 2.pptx
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
GE3151 UNIT II Study material .pdf
Introduction To Programming with Python Lecture 2
Unit 1- Part-2-Control and Loop Statements.pdf
Introduction to Python Part-1
2-functions.pptx_20240619_085610_0000.pdf
Python Flow Control
Python
Python interview questions and answers
Unit - 2 CAP.pptx
Programming in Arduino (Part 2)
Python interview questions and answers
Anton Kasyanov, Introduction to Python, Lecture2
Ad

More from SukhpreetSingh519414 (10)

PPTX
KIRSET24 template fggppt - Copy (1).pptx
PDF
Decimals intjsshshshshsjsjshdhdhsjsjsjdh
PPTX
python full notes data types string and tuple
PPTX
CPP-overviews notes variable data types notes
PDF
ppt notes python language operators and data
PDF
ppt notes for python language variable data types
PDF
C%20ARRAYS.pdf.pdf
PPTX
java exception.pptx
PPTX
finap ppt conference.pptx
PPTX
final security ppt.pptx
KIRSET24 template fggppt - Copy (1).pptx
Decimals intjsshshshshsjsjshdhdhsjsjsjdh
python full notes data types string and tuple
CPP-overviews notes variable data types notes
ppt notes python language operators and data
ppt notes for python language variable data types
C%20ARRAYS.pdf.pdf
java exception.pptx
finap ppt conference.pptx
final security ppt.pptx
Ad

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Cell Types and Its function , kingdom of life
PDF
RMMM.pdf make it easy to upload and study
PDF
Computing-Curriculum for Schools in Ghana
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Basic Mud Logging Guide for educational purpose
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
GDM (1) (1).pptx small presentation for students
Cell Types and Its function , kingdom of life
RMMM.pdf make it easy to upload and study
Computing-Curriculum for Schools in Ghana
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
TR - Agricultural Crops Production NC III.pdf
Insiders guide to clinical Medicine.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O7-L3 Supply Chain Operations - ICLT Program
Basic Mud Logging Guide for educational purpose
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPH.pptx obstetrics and gynecology in nursing

ppt python notes list tuple data types ope

  • 2. Conditional Statements  There comes situations in real life when we need to do some specific task and based on some specific conditions and, we decide what should we do next. Similarly there comes a situation in programming where a specific task is to be performed if a specific condition is True. In such cases, conditional statements can be used.  The following are the conditional statements provided by Python.  if  If else  Nested if
  • 3. If Statement  If the simple code of block is to be performed if the condition holds true then the if statement is used. Here the condition mentioned holds true then the code of the block runs otherwise not.  Syntax:  if condition:  # Statements to execute if  # condition is true
  • 4. If else Statement  In conditional if Statement the additional block of code is merged as else statement which is performed when if condition is false.  Syntax:  if (condition):  # Executes this block if  # condition is true  else:  # Executes this block if  # condition is false
  • 5. Nested if Statement  if statement can also be checked inside other if statement. This conditional statement is called a nested if statement. This means that inner if condition will be checked only if outer if condition is true and by this, we can see multiple conditions to be satisfied.  Syntax:  if (condition1):  # Executes when condition1 is true  if (condition2):  # Executes when condition2 is true  # if Block is end here  # if Block is end here
  • 6. Loops  Python programming language provides the following types of loops to handle looping requirements. Python provides three ways for executing the loops. While all the ways provide similar basic functionality, they differ in their syntax and condition-checking time.
  • 7. 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.  Syntax:  while expression: statement(s)
  • 8. For Loop  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.   Syntax:  for iterator_var in sequence: statements(s)
  • 9. Loop Control Statements  Loop control statements change execution from their normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements.  Continue Statement  the continue statement  in Python returns the  control to the beginning  of the loop.
  • 10. Break Statement  The break statement in Python brings control out of the loop.
  • 11. Functions  A function is a block of code which only runs when it is called.  You can pass data, known as parameters, into a function.  A function can return data as a result.
  • 12. Invoking Built In Functions  Python has various functions which are readily available. These functions are termed built in functions. On this reference page, you will be able to see all the built-in functions available in Python:  Python abs()  It returns the absolute and exact value of a given number  Python all()  It returns true when all the elements in iterable are true  Python chr()  It returns a Character from an Integer  Python classmethod()  It returns the class method for the provided function
  • 13. random() Function in Python  random(), simply speaking, is an inbuilt function of the random module in Python3 and it helps in the derivation of the python random list. Furthermore, the random module in Python provides access to some useful functions and one of them is able to facilitate the generation of random floating numbers, which is random(). Also, its syntax is random. random() python.  Syntax: random.random()  Parameters: Any parameter is not accepted by this method.  Returns: Random floating number between 0 and 1 is returned by this method.
  • 15. randint() Function in Python  randint() refers to an inbuilt function belonging to the random module in Python3. Furthermore, access is provided by random module provides access to some beneficial functions. Moreover, one of the functions is to generate random numbers, which is randint().  Syntax : randint(start, end)  Parameters : (start, end) : Both of them have to be integer-type values.  Returns : A random integer in the range [start, end] consisting of the endpoints. 
  • 17. Errors and Exceptions :  ValueError: Returns a ValueError when floating- point values are passed as parameters.  TypeError: TypeError is returned when anything other than numeric values is passed as parameters.