SlideShare a Scribd company logo
1 of 36
ADITYA COLLEGE OF ENGINEERING &
TECHNOLOGY
Python Programming
By
B SNV Ramana Murthy
Dept of CSE (AI & ML)
Aditya College of Engineering & Technology
Surampalem
Aditya College of Engineering & Technology
Python Programming
Types, Operators and Expressions: Types - Integers, Strings,
Booleans; Operators Arithmetic Operators, Comparison (Relational)
Operators, Assignment Operators, Logical Operators, Bitwise
Operators, Membership Operators, Identity Operators, Expressions
and order of evaluations, Control Flow- if, if-elif-else, for, while, break,
continue.
UNIT – II
BSNV R Murthy 2
Aditya College of Engineering & Technology
Python Programming
Python Data Types
BSNV R Murthy 3
Aditya College of Engineering & Technology
Python Programming
• Core Data Types
Numbers:
These are defined as “int”, “float”, and “complex” class in Python.
We can use the type function to know type or class of a variable.
Integers can be of any length, it is only limited by the memory variable.
A floating point number is accurate up to 15 decimal points.
For example, 1 is an Integer. 1.0 is floating point number.
The complex numbers are written in form, x+yj, where x is the Real part and y is
the imaginary part.
Python Data Types
BSNV R Murthy 4
Aditya College of Engineering & Technology
Python Programming
Procedure to know the Type of the Data:
Python Data Types
BSNV R Murthy 5
Aditya College of Engineering & Technology
Python Programming
• Core Data Types
Strings:
String is a sequence of characters.
We can use single quotes or double quotes to
represent the strings.
Multiline strings are denoted with Triple
Quotes, ‘ ‘ ‘ or “ “ “.
Example:
Python Data Types
BSNV R Murthy 6
Aditya College of Engineering & Technology
Python Programming
• Core Data Types
Strings:
We can get the character at the specified position by its index.
We can also get the substring from the index by specifying the range of the
substring.
The index always starts from zero
Example:
Python Data Types
BSNV R Murthy 7
Aditya College of Engineering & Technology
Python Programming
• Boolean Data Types
A Boolean variable can reference one of two values: True or False.
Boolean variables are commonly used as flags, which indicate whether specific
conditions exist.
Python Data Types
BSNV R Murthy 8
Aditya College of Engineering & Technology
Python Programming
• Compound Data Types
List: Is the Order collection of different types of items
Tuples: It is roughly like a list, but is immutable, that means, the tuple cannot be
modified once it is created.
Type Conversion:
Python Data Types
BSNV R Murthy 9
Aditya College of Engineering & Technology
Python Programming
• Expression: An Expression is a combination of operators and operands that
computes a value when executed by the Python interpreter.
• In python, an expression is formed using the usual mathematical operators and
operands (sometimes can be values also).
Operators
BSNV R Murthy 10
Aditya College of Engineering & Technology
Python Programming
• These operators are used to perform operations such as addition, subtraction,
multiplication, division and modulo division. For example, x=7, and y=3.
Arithmetic Operators
BSNV R Murthy 11
Aditya College of Engineering & Technology
Python Programming
• These operators are used to perform operations such as addition, subtraction,
multiplication, division and modulo division. For example, x=7, and y=3.
Arithmetic Operators
BSNV R Murthy 12
Aditya College of Engineering & Technology
Python Programming
• These operators are used to compare value. The operators can either return True
or False according to the condition. The table with following values for x=7 and
y=3.
Comparison (Relational) Operators
BSNV R Murthy 13
Aditya College of Engineering & Technology
Python Programming
• These operators are used to compare value. The operators can either return True
or False according to the condition. The table with following values for x=7 and
y=3.
Comparison (Relational) Operators
BSNV R Murthy 14
Aditya College of Engineering & Technology
Python Programming
• Bitwise operators act on operands as if they were string of binary digits. The operators operate bit
by bit. For example, x=2 (binary value is 10) and y=7 (Binary value is 111). The binary equivalent of
the decimal values of x and y will be 10 and 111 respectively.
Bitwise Operators
BSNV R Murthy 15
Aditya College of Engineering & Technology
Python Programming
• Bitwise operators act on operands as if they were string of binary digits. The operators operate bit
by bit. For example, x=2 (binary value is 10) and y=7 (Binary value is 111). The binary equivalent of
the decimal values of x and y will be 10 and 111 respectively.
Bitwise Operators
BSNV R Murthy 16
Aditya College of Engineering & Technology
Python Programming
• There are three logical operators: and, or, and not
Logical Operator
BSNV R Murthy 17
Aditya College of Engineering & Technology
Python Programming
• Assignment operator is used to assign values to the variable. For example, x=5 is
simple assignment operator. The same assignment operator can be
applied to all expressions that contain arithmetic operators such as,
*=, /=, -=, **=,%= etc.,
Assignment Operator
BSNV R Murthy 18
Aditya College of Engineering & Technology
Python Programming
• These operators are used to test whether a value or operand is there in the
sequence such as list, string, set, or dictionary. There are two membership
operators in python: in and not in. In the dictionary we can use to find the
presence of the key, not the value.
Membership Operators
BSNV R Murthy 19
Aditya College of Engineering & Technology
Python Programming
Membership Operators
BSNV R Murthy 20
Aditya College of Engineering & Technology
Python Programming
• These are used to check if two values (variable) are located on the same part of
the memory. If the x is a variable contain some value, it is assigned to variable y.
Now both variables are pointing (referring) to the same location on the memory
as shown in the example program.
Identity Operators
BSNV R Murthy 21
Aditya College of Engineering & Technology
Python Programming
• These are used to check if two values (variable) are located on the same part of
the memory. If the x is a variable contain some value, it is assigned to variable y.
Now both variables are pointing (referring) to the same location on the memory
as shown in the example program.
Identity Operators
BSNV R Murthy 22
Aditya College of Engineering & Technology
Python Programming
Precedence of the Operators
BSNV R Murthy 23
Aditya College of Engineering & Technology
Python Programming
In all most all programming languages the control flow statements are classified
as
Selection Statements
Loop Statements or Iterative Statement and
Jump Statements.
Under the Selection statements in Python we have if, elif and else statement.
Under the loop statements we have for and while statements.
Under the Jump statements we have break, continue and pass statements.
Control Flow
BSNV R Murthy 24
Aditya College of Engineering & Technology
Python Programming
The if statement is used for conditional execution. An if statement is followed by a Boolean
expression, which is evaluated to either True or False. If Boolean expression is evaluated to True,
the block which contains one or more statements will be executed. Otherwise, the block followed
by the “else” statement is executed. The general form of if statement will be as follow in Python:
if boolena_expression:
statement(s) # block of statements inside if
else:
statement(s) # block of statements inside else
If statement
BSNV R Murthy 25
Aditya College of Engineering & Technology
Python Programming
This combination of statements is used, whenever; one among multiple alternatives needs to be
selected. It selects exactly one block of statements if and only if, one of the Boolean expressions is
evaluated to True, otherwise block inside the “else” statement will be executed, if present.
General form of if-elif-else will be as follow:
if(boolean_expression):
Block of statements
elif(boolean_expression):
Block of statements
elif(boolean_expression):
else:
Block of statements
if –elif-else statements
BSNV R Murthy 26
Aditya College of Engineering & Technology
Python Programming
if –elif-else statements
BSNV R Murthy 27
Aditya College of Engineering & Technology
Python Programming
The loops are used to execute some finite number of statements in block repeatedly until some
condition is satisfied. There are two loop statements in Python, for and while.
for statement
For loops iterate over a given sequence or list. It is helpful in running a loop on each item in the list. The
general form of “for” loop in Python will be as follow:
Here variable is the name of the variable. And in is the keyword. Inside the square brackets a sequence of
values are separated by comma. In Python, a comma-separated sequence of data items that are enclosed in
a set of square brackets is called a list. The list is created with help of [] square brackets. The list also can be
created with help of tuple. We can also use range() function to create the list. The general form of the
range() function will be as follow:
range(number) –ex: range(10) –It takes all the values from 0 to 9
range(start,stop, interval_size) –ex: range(2,10,2)-It lists all the numbers such as 2,4,6,8.
Range(start,stop)-ex: range(1,6), lists all the numbers from 1to 5, but not 6. Here, by default the
interval size is 1.
Loop Statements
BSNV R Murthy 28
Aditya College of Engineering & Technology
Python Programming
Loop Statements
BSNV R Murthy 29
Aditya College of Engineering & Technology
Python Programming
While loops repeat as long as a certain boolean condition is met. The block of statements is
repeatedly executed as long as the condition is evaluated to True. The general form of while will
be as follow:
while statement
BSNV R Murthy 30
Aditya College of Engineering & Technology
Python Programming
Loop statements may have an else clause
It is executed when the loop terminates through exhaustion of the list (with for loop)
It is executed when the condition becomes false (with while loop) ,But not when the loop is
terminated by a break statement
Example: printing all primes numbers up to 1000
ELSE for a loop
BSNV R Murthy 31
Aditya College of Engineering & Technology
Python Programming
we have three jump statements: break, continue and pass.
break statement
It terminates the current loop and resumes execution at the next statement, just like the traditional break
statement in C.
The most common use for break is when some external condition is triggered requiring a hasty exit from a
loop. The break statement can be used in both while and for loops.
If you are using nested loops, the break statement stops the execution of the innermost loop and start
executing the next line of code after the block.
Syntax The syntax for a break statement in Python is as follows −
break
Jump Statements
BSNV R Murthy 32
Aditya College of Engineering & Technology
Python Programming
Jump Statements
BSNV R Murthy 33
Aditya College of Engineering & Technology
Python Programming
It returns the control to the beginning of the while loop..
The continue statement rejects all the remaining statements in the current iteration of the loop
and moves the control back to the top of the loop.
The continue statement can be used in both while and for loops.
Syntax – continue
Continue Statement
BSNV R Murthy 34
Aditya College of Engineering & Technology
Python Programming
The pass statement does nothing
It can be used when a statement is required syntactically but the program requires no action
Example: creating an infinite loop that does nothing
while True: pass
Pass statement
BSNV R Murthy 35
ADITYA COLLEGE OF ENGINEERING &
TECHNOLOGY
Thank You

More Related Content

Similar to UNIT II_python Programming_aditya College

trisha comp ppt.pptx
trisha comp ppt.pptxtrisha comp ppt.pptx
trisha comp ppt.pptxTapaswini14
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptxrohithprabhas1
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statementsİbrahim Kürce
 
The Awesome Python Class Part-3
The Awesome Python Class Part-3The Awesome Python Class Part-3
The Awesome Python Class Part-3Binay Kumar Ray
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1Devashish Kumar
 
chapter-1-review-of-python-basics-copy.pdf
chapter-1-review-of-python-basics-copy.pdfchapter-1-review-of-python-basics-copy.pdf
chapter-1-review-of-python-basics-copy.pdfSangeethManojKumar
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptxYusuf Ayuba
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdfalaparthi
 
L6 - Loops.pptx
L6 - Loops.pptxL6 - Loops.pptx
L6 - Loops.pptxEloAOgardo
 
L6 - Loops.pptx
L6 - Loops.pptxL6 - Loops.pptx
L6 - Loops.pptxEloAOgardo
 
L5 - Data Types, Keywords.pptx
L5 - Data Types, Keywords.pptxL5 - Data Types, Keywords.pptx
L5 - Data Types, Keywords.pptxEloAOgardo
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Chariza Pladin
 
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxchapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxJahnavi113937
 
PE1 Module 2.ppt
PE1 Module 2.pptPE1 Module 2.ppt
PE1 Module 2.pptbalewayalew
 

Similar to UNIT II_python Programming_aditya College (20)

trisha comp ppt.pptx
trisha comp ppt.pptxtrisha comp ppt.pptx
trisha comp ppt.pptx
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Python
PythonPython
Python
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
The Awesome Python Class Part-3
The Awesome Python Class Part-3The Awesome Python Class Part-3
The Awesome Python Class Part-3
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
 
chapter-1-review-of-python-basics-copy.pdf
chapter-1-review-of-python-basics-copy.pdfchapter-1-review-of-python-basics-copy.pdf
chapter-1-review-of-python-basics-copy.pdf
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptx
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdf
 
L6 - Loops.pptx
L6 - Loops.pptxL6 - Loops.pptx
L6 - Loops.pptx
 
L6 - Loops.pptx
L6 - Loops.pptxL6 - Loops.pptx
L6 - Loops.pptx
 
Unit-I-PPT-1.ppt
Unit-I-PPT-1.pptUnit-I-PPT-1.ppt
Unit-I-PPT-1.ppt
 
L5 - Data Types, Keywords.pptx
L5 - Data Types, Keywords.pptxL5 - Data Types, Keywords.pptx
L5 - Data Types, Keywords.pptx
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
 
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxchapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Python basics
Python basicsPython basics
Python basics
 
PE1 Module 2.ppt
PE1 Module 2.pptPE1 Module 2.ppt
PE1 Module 2.ppt
 

More from Ramanamurthy Banda

UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeRamanamurthy Banda
 
Python Programming Unit1_Aditya College of Engg & Tech
Python Programming Unit1_Aditya College of Engg & TechPython Programming Unit1_Aditya College of Engg & Tech
Python Programming Unit1_Aditya College of Engg & TechRamanamurthy Banda
 
UnSupervised Machincs4811-ch23a-clustering.ppt
UnSupervised Machincs4811-ch23a-clustering.pptUnSupervised Machincs4811-ch23a-clustering.ppt
UnSupervised Machincs4811-ch23a-clustering.pptRamanamurthy Banda
 
Virtualization for Windows - Seminar.pptx
Virtualization for Windows - Seminar.pptxVirtualization for Windows - Seminar.pptx
Virtualization for Windows - Seminar.pptxRamanamurthy Banda
 

More from Ramanamurthy Banda (7)

UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
 
Python Programming Unit1_Aditya College of Engg & Tech
Python Programming Unit1_Aditya College of Engg & TechPython Programming Unit1_Aditya College of Engg & Tech
Python Programming Unit1_Aditya College of Engg & Tech
 
UnSupervised Machincs4811-ch23a-clustering.ppt
UnSupervised Machincs4811-ch23a-clustering.pptUnSupervised Machincs4811-ch23a-clustering.ppt
UnSupervised Machincs4811-ch23a-clustering.ppt
 
Introduction.ppt
Introduction.pptIntroduction.ppt
Introduction.ppt
 
Virtualization for Windows - Seminar.pptx
Virtualization for Windows - Seminar.pptxVirtualization for Windows - Seminar.pptx
Virtualization for Windows - Seminar.pptx
 
UML-casestudy.ppt
UML-casestudy.pptUML-casestudy.ppt
UML-casestudy.ppt
 
Binomial
BinomialBinomial
Binomial
 

Recently uploaded

Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 

Recently uploaded (20)

Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 

UNIT II_python Programming_aditya College

  • 1. ADITYA COLLEGE OF ENGINEERING & TECHNOLOGY Python Programming By B SNV Ramana Murthy Dept of CSE (AI & ML) Aditya College of Engineering & Technology Surampalem
  • 2. Aditya College of Engineering & Technology Python Programming Types, Operators and Expressions: Types - Integers, Strings, Booleans; Operators Arithmetic Operators, Comparison (Relational) Operators, Assignment Operators, Logical Operators, Bitwise Operators, Membership Operators, Identity Operators, Expressions and order of evaluations, Control Flow- if, if-elif-else, for, while, break, continue. UNIT – II BSNV R Murthy 2
  • 3. Aditya College of Engineering & Technology Python Programming Python Data Types BSNV R Murthy 3
  • 4. Aditya College of Engineering & Technology Python Programming • Core Data Types Numbers: These are defined as “int”, “float”, and “complex” class in Python. We can use the type function to know type or class of a variable. Integers can be of any length, it is only limited by the memory variable. A floating point number is accurate up to 15 decimal points. For example, 1 is an Integer. 1.0 is floating point number. The complex numbers are written in form, x+yj, where x is the Real part and y is the imaginary part. Python Data Types BSNV R Murthy 4
  • 5. Aditya College of Engineering & Technology Python Programming Procedure to know the Type of the Data: Python Data Types BSNV R Murthy 5
  • 6. Aditya College of Engineering & Technology Python Programming • Core Data Types Strings: String is a sequence of characters. We can use single quotes or double quotes to represent the strings. Multiline strings are denoted with Triple Quotes, ‘ ‘ ‘ or “ “ “. Example: Python Data Types BSNV R Murthy 6
  • 7. Aditya College of Engineering & Technology Python Programming • Core Data Types Strings: We can get the character at the specified position by its index. We can also get the substring from the index by specifying the range of the substring. The index always starts from zero Example: Python Data Types BSNV R Murthy 7
  • 8. Aditya College of Engineering & Technology Python Programming • Boolean Data Types A Boolean variable can reference one of two values: True or False. Boolean variables are commonly used as flags, which indicate whether specific conditions exist. Python Data Types BSNV R Murthy 8
  • 9. Aditya College of Engineering & Technology Python Programming • Compound Data Types List: Is the Order collection of different types of items Tuples: It is roughly like a list, but is immutable, that means, the tuple cannot be modified once it is created. Type Conversion: Python Data Types BSNV R Murthy 9
  • 10. Aditya College of Engineering & Technology Python Programming • Expression: An Expression is a combination of operators and operands that computes a value when executed by the Python interpreter. • In python, an expression is formed using the usual mathematical operators and operands (sometimes can be values also). Operators BSNV R Murthy 10
  • 11. Aditya College of Engineering & Technology Python Programming • These operators are used to perform operations such as addition, subtraction, multiplication, division and modulo division. For example, x=7, and y=3. Arithmetic Operators BSNV R Murthy 11
  • 12. Aditya College of Engineering & Technology Python Programming • These operators are used to perform operations such as addition, subtraction, multiplication, division and modulo division. For example, x=7, and y=3. Arithmetic Operators BSNV R Murthy 12
  • 13. Aditya College of Engineering & Technology Python Programming • These operators are used to compare value. The operators can either return True or False according to the condition. The table with following values for x=7 and y=3. Comparison (Relational) Operators BSNV R Murthy 13
  • 14. Aditya College of Engineering & Technology Python Programming • These operators are used to compare value. The operators can either return True or False according to the condition. The table with following values for x=7 and y=3. Comparison (Relational) Operators BSNV R Murthy 14
  • 15. Aditya College of Engineering & Technology Python Programming • Bitwise operators act on operands as if they were string of binary digits. The operators operate bit by bit. For example, x=2 (binary value is 10) and y=7 (Binary value is 111). The binary equivalent of the decimal values of x and y will be 10 and 111 respectively. Bitwise Operators BSNV R Murthy 15
  • 16. Aditya College of Engineering & Technology Python Programming • Bitwise operators act on operands as if they were string of binary digits. The operators operate bit by bit. For example, x=2 (binary value is 10) and y=7 (Binary value is 111). The binary equivalent of the decimal values of x and y will be 10 and 111 respectively. Bitwise Operators BSNV R Murthy 16
  • 17. Aditya College of Engineering & Technology Python Programming • There are three logical operators: and, or, and not Logical Operator BSNV R Murthy 17
  • 18. Aditya College of Engineering & Technology Python Programming • Assignment operator is used to assign values to the variable. For example, x=5 is simple assignment operator. The same assignment operator can be applied to all expressions that contain arithmetic operators such as, *=, /=, -=, **=,%= etc., Assignment Operator BSNV R Murthy 18
  • 19. Aditya College of Engineering & Technology Python Programming • These operators are used to test whether a value or operand is there in the sequence such as list, string, set, or dictionary. There are two membership operators in python: in and not in. In the dictionary we can use to find the presence of the key, not the value. Membership Operators BSNV R Murthy 19
  • 20. Aditya College of Engineering & Technology Python Programming Membership Operators BSNV R Murthy 20
  • 21. Aditya College of Engineering & Technology Python Programming • These are used to check if two values (variable) are located on the same part of the memory. If the x is a variable contain some value, it is assigned to variable y. Now both variables are pointing (referring) to the same location on the memory as shown in the example program. Identity Operators BSNV R Murthy 21
  • 22. Aditya College of Engineering & Technology Python Programming • These are used to check if two values (variable) are located on the same part of the memory. If the x is a variable contain some value, it is assigned to variable y. Now both variables are pointing (referring) to the same location on the memory as shown in the example program. Identity Operators BSNV R Murthy 22
  • 23. Aditya College of Engineering & Technology Python Programming Precedence of the Operators BSNV R Murthy 23
  • 24. Aditya College of Engineering & Technology Python Programming In all most all programming languages the control flow statements are classified as Selection Statements Loop Statements or Iterative Statement and Jump Statements. Under the Selection statements in Python we have if, elif and else statement. Under the loop statements we have for and while statements. Under the Jump statements we have break, continue and pass statements. Control Flow BSNV R Murthy 24
  • 25. Aditya College of Engineering & Technology Python Programming The if statement is used for conditional execution. An if statement is followed by a Boolean expression, which is evaluated to either True or False. If Boolean expression is evaluated to True, the block which contains one or more statements will be executed. Otherwise, the block followed by the “else” statement is executed. The general form of if statement will be as follow in Python: if boolena_expression: statement(s) # block of statements inside if else: statement(s) # block of statements inside else If statement BSNV R Murthy 25
  • 26. Aditya College of Engineering & Technology Python Programming This combination of statements is used, whenever; one among multiple alternatives needs to be selected. It selects exactly one block of statements if and only if, one of the Boolean expressions is evaluated to True, otherwise block inside the “else” statement will be executed, if present. General form of if-elif-else will be as follow: if(boolean_expression): Block of statements elif(boolean_expression): Block of statements elif(boolean_expression): else: Block of statements if –elif-else statements BSNV R Murthy 26
  • 27. Aditya College of Engineering & Technology Python Programming if –elif-else statements BSNV R Murthy 27
  • 28. Aditya College of Engineering & Technology Python Programming The loops are used to execute some finite number of statements in block repeatedly until some condition is satisfied. There are two loop statements in Python, for and while. for statement For loops iterate over a given sequence or list. It is helpful in running a loop on each item in the list. The general form of “for” loop in Python will be as follow: Here variable is the name of the variable. And in is the keyword. Inside the square brackets a sequence of values are separated by comma. In Python, a comma-separated sequence of data items that are enclosed in a set of square brackets is called a list. The list is created with help of [] square brackets. The list also can be created with help of tuple. We can also use range() function to create the list. The general form of the range() function will be as follow: range(number) –ex: range(10) –It takes all the values from 0 to 9 range(start,stop, interval_size) –ex: range(2,10,2)-It lists all the numbers such as 2,4,6,8. Range(start,stop)-ex: range(1,6), lists all the numbers from 1to 5, but not 6. Here, by default the interval size is 1. Loop Statements BSNV R Murthy 28
  • 29. Aditya College of Engineering & Technology Python Programming Loop Statements BSNV R Murthy 29
  • 30. Aditya College of Engineering & Technology Python Programming While loops repeat as long as a certain boolean condition is met. The block of statements is repeatedly executed as long as the condition is evaluated to True. The general form of while will be as follow: while statement BSNV R Murthy 30
  • 31. Aditya College of Engineering & Technology Python Programming Loop statements may have an else clause It is executed when the loop terminates through exhaustion of the list (with for loop) It is executed when the condition becomes false (with while loop) ,But not when the loop is terminated by a break statement Example: printing all primes numbers up to 1000 ELSE for a loop BSNV R Murthy 31
  • 32. Aditya College of Engineering & Technology Python Programming we have three jump statements: break, continue and pass. break statement It terminates the current loop and resumes execution at the next statement, just like the traditional break statement in C. The most common use for break is when some external condition is triggered requiring a hasty exit from a loop. The break statement can be used in both while and for loops. If you are using nested loops, the break statement stops the execution of the innermost loop and start executing the next line of code after the block. Syntax The syntax for a break statement in Python is as follows − break Jump Statements BSNV R Murthy 32
  • 33. Aditya College of Engineering & Technology Python Programming Jump Statements BSNV R Murthy 33
  • 34. Aditya College of Engineering & Technology Python Programming It returns the control to the beginning of the while loop.. The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop. The continue statement can be used in both while and for loops. Syntax – continue Continue Statement BSNV R Murthy 34
  • 35. Aditya College of Engineering & Technology Python Programming The pass statement does nothing It can be used when a statement is required syntactically but the program requires no action Example: creating an infinite loop that does nothing while True: pass Pass statement BSNV R Murthy 35
  • 36. ADITYA COLLEGE OF ENGINEERING & TECHNOLOGY Thank You