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

PPTX
Chapter - 3.pptx
PDF
Python Programming Module 3 (2).pdf
PPTX
Loops in Python
PDF
2 Python Basics II meeting 2 tunghai university pdf
PPTX
1. control structures in the python.pptx
PDF
Python unit 2 M.sc cs
PPTX
UNIT – 3.pptx for first year engineering
PPTX
Programming with python
Chapter - 3.pptx
Python Programming Module 3 (2).pdf
Loops in Python
2 Python Basics II meeting 2 tunghai university pdf
1. control structures in the python.pptx
Python unit 2 M.sc cs
UNIT – 3.pptx for first year engineering
Programming with python

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

PDF
python notes.pdf
PDF
pythonQuick.pdf
PDF
python 34💭.pdf
PPTX
made it easy: python quick reference for beginners
PPTX
module 2.pptx
PPTX
Python programing
PDF
Python revision tour i
PPTX
Module_2_1_Building Python Programs_Final.pptx
PPTX
module 3 BTECH FIRST YEAR ATP APJ KTU PYTHON
PDF
GE3151_PSPP_UNIT_3_Notes
PPT
python fundamental for beginner course .ppt
PPTX
An Introduction : Python
PPTX
Python programming –part 3
PPTX
PPT-GIT.pptx
PPTX
Format of first slide for main PPT-GIT.pptx
PPTX
Anish PPT-GIT.pptx
PPTX
Chapter 2-Python and control flow statement.pptx
PPTX
Bikalpa_Thapa_Python_Programming_(Basics).pptx
PPTX
Introduction to Python Part-1
PPT
Control structures pyhton
python notes.pdf
pythonQuick.pdf
python 34💭.pdf
made it easy: python quick reference for beginners
module 2.pptx
Python programing
Python revision tour i
Module_2_1_Building Python Programs_Final.pptx
module 3 BTECH FIRST YEAR ATP APJ KTU PYTHON
GE3151_PSPP_UNIT_3_Notes
python fundamental for beginner course .ppt
An Introduction : Python
Python programming –part 3
PPT-GIT.pptx
Format of first slide for main PPT-GIT.pptx
Anish PPT-GIT.pptx
Chapter 2-Python and control flow statement.pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Introduction to Python Part-1
Control structures pyhton
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)

PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
RMMM.pdf make it easy to upload and study
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
master seminar digital applications in india
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Yogi Goddess Pres Conference Studio Updates
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
RMMM.pdf make it easy to upload and study
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
master seminar digital applications in india
O7-L3 Supply Chain Operations - ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
A systematic review of self-coping strategies used by university students to ...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Final Presentation General Medicine 03-08-2024.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
01-Introduction-to-Information-Management.pdf
Cell Types and Its function , kingdom of life
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Computing-Curriculum for Schools in Ghana
Microbial diseases, their pathogenesis and prophylaxis
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Yogi Goddess Pres Conference Studio Updates

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.