SlideShare ist ein Scribd-Unternehmen logo
1 von 16
The Awesome
Input, Iterators/Generators, Range,
Operator, Control Flow.
Part-3
Summary of Previous Parts
We are done with discussing the greatness of python, Installation, Editor
selection, Environment setup and package installation.
We have also discussed Data types in python. Basic Data structures, their
syntaxes and their usage.
We will move forward with lot many things,
I hope you enjoy the show.
2
Input
The basic step of any programming language, How to take input from the user.
raw_input, input
3
In python 3.X raw_input is depreciated.
Iterators
Basically you can say any objects in python that has a attribute __next__, is an
iterator.
Eg, [0, 1, 2, 3, 4] is an iterator. It has 5 elements starting from 0 and has next.
You can loop over an iterator as many times as possible, as it saves the iterable values in
memory.
4
Generators
Generators are iterators which never stores all the elements in memory.
Generator Expressions are generator version of list comprehensions. They
look like list comprehensions, but returns a generator back instead of a list.
numbers = (x for x in range(5))
here numbers is a generator, having value <generator object <genexpr> at 0x401f08>
The values are never stored in memory, and they are revoked when needed.
The value can be accessed once only.
They generate the values on the fly. 5
Range vs Xrange
Range is a really cool thing in python.
It’s mainly used for mathematical functions
or iteration.
range is basically a list of numbers. from first
index to n-1 index.
If first index is not given then it takes it as 0.
eg, numbers = range(5), numbers is [0, 1, 2, 3,
4]
In python 2.x the output of range is an
iterator. 6
Xrange is even better than range.
Almost the same as range but it behaves as
a generator.
The output starts from the first index iterates
to n-1 and saves in an xrange object.
It does not load all data to memory so it’s
faster.
In python 3.x there is no xrange but range
works like xrange and does not load
values to memory.
Operators
Arithmetic Operators
Comparison (Relational) Operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
7
There are several operators in
python
Arithmetic Operators Comparison
Operator
Addition (+), used for sum.
Subtraction (-), user for difference.
Multiplication (*), used for product.
Division (/), used to divide.
Exponent (**), use to add power to any
number.
Modulus (%), used to get remainder from
division.
Floor division (//), gives the floor value of the 8
Equality (==), check for equality.
Inequality (<>, !=), check for not equal.
Greater than (>), Lesser than (<), for
comparison.
Greater than or equal to (>=), Less than or
equal to (<=), for comparison.
Assignment Operator Logical Operators
Assignment (=).
Add AND (+=), sums and assigns.
Subtract AND (-=), subtracts and assigns.
Multiply AND (*=), multiplies and assigns.
Divide AND (+=), divides and assigns.
Modulus AND (%=), assigns the reminder.
Exponent AND (**=), Assigns the final value
after the exponent multiplication.
9
There are 3 logical operators mainly available
in python.
and
or
not
You can directly use the key words for using
them.
Beware &, | and ~ has different usage in
python. These will not work as logical
operators.
Membership Operator
Basically two membership
operators.
in and not in
in checks whether the var is a
member of the sequence or not.
not in check whether the var is not
a member of the sequence or
not.
10
Bitwise Operator
Assume a = 60 and b = 13. so binary format will be
a = 0011 1100 and b = 0000 1101
Binary AND (&), a & b is 0000 1100.
Binary OR (&), a & b is 0011 1101.
Binary XOR (&), a & b is 0011 0001.
Binary 1’s Compliment (&), (~a ) = -61 (means 1100
0011 in 2's complement form due to a signed
binary number..
Binary Left Shift (&), a << = 240 (means 1111 0000).
Binary Right Shift (&), a >> = 15 (means 0000 1111).
Identity Operator
Basically two identity operators.
is and is not
is checks whether the two
variables are pointing to the
same object or not.
is not check whether the two
Control Flow
Basically it means the flow of your written program
that you can control with your conditions.
Loops
for loop
while loop
breaking and whitespaces
else with loops
Branches 11
Loops
FOR Loop
Unlike conventional for loops, for loop in
python uses membership operator for
iteration.
Syntax:
for i in range(5):
print i * i
Output will be
0 1 4 9 16
12
While Loop
A while loop repeats a sequence of
statements until some condition becomes
false.
Syntax:
x = 5
while x > 0:
print (x)
x = x - 1
Output will be
5 4 3 2 1
Breaking loops Else with loops
With loops in python two things comes in
mind. breaking and white spaces.
we can use keyword break inside any loop
and the loop instantly stop iterating when
break is executed.
Similarly we have continue keyword, when
encountered the interpreter simply skips
every next steps inside the loop and
comes to the next iteration.
Whitespace plays a vital role in python.
every block that is indented inside the loop is
13
The awesomeness of python is you can use
else not only with if but also with loops
and exceptions.
Every loop in this world is driven by some
condition. If that condition is met for the
iteration then it goes inside of the loop
else it goes inside of else.
That makes sense right ?
You can simply reduce a bunch of code
simply using else with loops.
You can use it with both for and while.
Branches
There is basically only one kind of branch in
Python, the 'if' statement. The simplest
form of the if statement simple executes a
block of code only if a given predicate is
true, and skips over it if the predicate is
false.
if x > 0:
print "Positive"
if x < 0:
print "Negative"
14
"elif" branches onto the if statement.
Note, it will stop checking branches as soon
as it finds a true predicate, and skip the
rest of the if statement.
x = -6
if x > 0:
print "Positive"
elif x == 0:
print "Zero"
else:
print "Negative"
Order of operations
When more than one operator appears in an
expression, the order of evaluation
depends on the rules of precedence.
For mathematical operators, Python follows
mathematical convention.
The acronym PEMDAS is a useful way to
remember the rules:
1. P : Parenthesis
2. E : Exponential
3. M : Multiplication
4. D : Division
5. A : Addition
6. S : Subtraction
15
ThanksStay Tuned for the next part. Enjoy !!
16

Weitere ähnliche Inhalte

Was ist angesagt?

Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2Anton Kasyanov
 
Introduction To Programming with Python-3
Introduction To Programming with Python-3Introduction To Programming with Python-3
Introduction To Programming with Python-3Syed Farjad Zia Zaidi
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answerskavinilavuG
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1Syed Farjad Zia Zaidi
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundationKevlin Henney
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1Prerna Sharma
 
Python Interview Questions For Freshers
Python Interview Questions For FreshersPython Interview Questions For Freshers
Python Interview Questions For Fresherszynofustechnology
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python FundamentalsPraveen M Jigajinni
 
Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2Umar Ali
 
Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityMohd Sajjad
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| FundamentalsMohd Sajjad
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Syed Farjad Zia Zaidi
 

Was ist angesagt? (20)

Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2
 
Python Session - 5
Python Session - 5Python Session - 5
Python Session - 5
 
Python second ppt
Python second pptPython second ppt
Python second ppt
 
Python Session - 4
Python Session - 4Python Session - 4
Python Session - 4
 
Introduction To Programming with Python-3
Introduction To Programming with Python-3Introduction To Programming with Python-3
Introduction To Programming with Python-3
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Notes on c++
Notes on c++Notes on c++
Notes on c++
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
 
Python advance
Python advancePython advance
Python advance
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1
 
Python Interview Questions For Freshers
Python Interview Questions For FreshersPython Interview Questions For Freshers
Python Interview Questions For Freshers
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2
 
Advance python
Advance pythonAdvance python
Advance python
 
Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 

Andere mochten auch

8 grejer som storföretag kan lära av startups
8 grejer som storföretag kan lära av startups8 grejer som storföretag kan lära av startups
8 grejer som storföretag kan lära av startupsIdea Hunt
 
I huvudet på en cloudarkitekt | cloudcache.io
I huvudet på en cloudarkitekt | cloudcache.ioI huvudet på en cloudarkitekt | cloudcache.io
I huvudet på en cloudarkitekt | cloudcache.iowelovecloud
 
ASAS 2013 - Agility and the essence of software architecture
ASAS 2013 - Agility and the essence of software architectureASAS 2013 - Agility and the essence of software architecture
ASAS 2013 - Agility and the essence of software architectureAvisi B.V.
 
Python 3.5: An agile, general-purpose development language.
Python 3.5: An agile, general-purpose development language.Python 3.5: An agile, general-purpose development language.
Python 3.5: An agile, general-purpose development language.Carlos Miguel Ferreira
 
Introduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculusIntroduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculusKim Leo
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptMohd Saeed
 
The Zen of Python
The Zen of PythonThe Zen of Python
The Zen of PythonDavid Arcos
 
Support Vector Machine without tears
Support Vector Machine without tearsSupport Vector Machine without tears
Support Vector Machine without tearsAnkit Sharma
 
Linear regression without tears
Linear regression without tearsLinear regression without tears
Linear regression without tearsAnkit Sharma
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 

Andere mochten auch (14)

8 grejer som storföretag kan lära av startups
8 grejer som storföretag kan lära av startups8 grejer som storföretag kan lära av startups
8 grejer som storföretag kan lära av startups
 
I huvudet på en cloudarkitekt | cloudcache.io
I huvudet på en cloudarkitekt | cloudcache.ioI huvudet på en cloudarkitekt | cloudcache.io
I huvudet på en cloudarkitekt | cloudcache.io
 
Grunt och gulp
Grunt och gulpGrunt och gulp
Grunt och gulp
 
Learn python 1
Learn python 1Learn python 1
Learn python 1
 
ASAS 2013 - Agility and the essence of software architecture
ASAS 2013 - Agility and the essence of software architectureASAS 2013 - Agility and the essence of software architecture
ASAS 2013 - Agility and the essence of software architecture
 
Python 3.5: An agile, general-purpose development language.
Python 3.5: An agile, general-purpose development language.Python 3.5: An agile, general-purpose development language.
Python 3.5: An agile, general-purpose development language.
 
Introduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculusIntroduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculus
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
 
The Zen of Python
The Zen of PythonThe Zen of Python
The Zen of Python
 
Python on AWS Lambda
Python on AWS Lambda Python on AWS Lambda
Python on AWS Lambda
 
Support Vector Machine without tears
Support Vector Machine without tearsSupport Vector Machine without tears
Support Vector Machine without tears
 
Linear regression without tears
Linear regression without tearsLinear regression without tears
Linear regression without tears
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Ähnlich wie The Awesome Python Class Part-3

Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answersRojaPriya
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experiencedzynofustechnology
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptxrohithprabhas1
 
1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdfMaheshGour5
 
UNIT II_python Programming_aditya College
UNIT II_python Programming_aditya CollegeUNIT II_python Programming_aditya College
UNIT II_python Programming_aditya CollegeRamanamurthy Banda
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning ParrotAI
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golangwww.ixxo.io
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python BasicsRaghunath A
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1Devashish Kumar
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.pptjaba kumar
 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdfpaijitk
 

Ähnlich wie The Awesome Python Class Part-3 (20)

Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
 
Java unit 3
Java unit 3Java unit 3
Java unit 3
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Python programming
Python  programmingPython  programming
Python programming
 
1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdf
 
UNIT II_python Programming_aditya College
UNIT II_python Programming_aditya CollegeUNIT II_python Programming_aditya College
UNIT II_python Programming_aditya College
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
 
Python
PythonPython
Python
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golang
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python Basics
 
Python
PythonPython
Python
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdf
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
 

Kürzlich hochgeladen

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(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
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 

Kürzlich hochgeladen (20)

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.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
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 

The Awesome Python Class Part-3

  • 1. The Awesome Input, Iterators/Generators, Range, Operator, Control Flow. Part-3
  • 2. Summary of Previous Parts We are done with discussing the greatness of python, Installation, Editor selection, Environment setup and package installation. We have also discussed Data types in python. Basic Data structures, their syntaxes and their usage. We will move forward with lot many things, I hope you enjoy the show. 2
  • 3. Input The basic step of any programming language, How to take input from the user. raw_input, input 3 In python 3.X raw_input is depreciated.
  • 4. Iterators Basically you can say any objects in python that has a attribute __next__, is an iterator. Eg, [0, 1, 2, 3, 4] is an iterator. It has 5 elements starting from 0 and has next. You can loop over an iterator as many times as possible, as it saves the iterable values in memory. 4
  • 5. Generators Generators are iterators which never stores all the elements in memory. Generator Expressions are generator version of list comprehensions. They look like list comprehensions, but returns a generator back instead of a list. numbers = (x for x in range(5)) here numbers is a generator, having value <generator object <genexpr> at 0x401f08> The values are never stored in memory, and they are revoked when needed. The value can be accessed once only. They generate the values on the fly. 5
  • 6. Range vs Xrange Range is a really cool thing in python. It’s mainly used for mathematical functions or iteration. range is basically a list of numbers. from first index to n-1 index. If first index is not given then it takes it as 0. eg, numbers = range(5), numbers is [0, 1, 2, 3, 4] In python 2.x the output of range is an iterator. 6 Xrange is even better than range. Almost the same as range but it behaves as a generator. The output starts from the first index iterates to n-1 and saves in an xrange object. It does not load all data to memory so it’s faster. In python 3.x there is no xrange but range works like xrange and does not load values to memory.
  • 7. Operators Arithmetic Operators Comparison (Relational) Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators Identity Operators 7 There are several operators in python
  • 8. Arithmetic Operators Comparison Operator Addition (+), used for sum. Subtraction (-), user for difference. Multiplication (*), used for product. Division (/), used to divide. Exponent (**), use to add power to any number. Modulus (%), used to get remainder from division. Floor division (//), gives the floor value of the 8 Equality (==), check for equality. Inequality (<>, !=), check for not equal. Greater than (>), Lesser than (<), for comparison. Greater than or equal to (>=), Less than or equal to (<=), for comparison.
  • 9. Assignment Operator Logical Operators Assignment (=). Add AND (+=), sums and assigns. Subtract AND (-=), subtracts and assigns. Multiply AND (*=), multiplies and assigns. Divide AND (+=), divides and assigns. Modulus AND (%=), assigns the reminder. Exponent AND (**=), Assigns the final value after the exponent multiplication. 9 There are 3 logical operators mainly available in python. and or not You can directly use the key words for using them. Beware &, | and ~ has different usage in python. These will not work as logical operators.
  • 10. Membership Operator Basically two membership operators. in and not in in checks whether the var is a member of the sequence or not. not in check whether the var is not a member of the sequence or not. 10 Bitwise Operator Assume a = 60 and b = 13. so binary format will be a = 0011 1100 and b = 0000 1101 Binary AND (&), a & b is 0000 1100. Binary OR (&), a & b is 0011 1101. Binary XOR (&), a & b is 0011 0001. Binary 1’s Compliment (&), (~a ) = -61 (means 1100 0011 in 2's complement form due to a signed binary number.. Binary Left Shift (&), a << = 240 (means 1111 0000). Binary Right Shift (&), a >> = 15 (means 0000 1111). Identity Operator Basically two identity operators. is and is not is checks whether the two variables are pointing to the same object or not. is not check whether the two
  • 11. Control Flow Basically it means the flow of your written program that you can control with your conditions. Loops for loop while loop breaking and whitespaces else with loops Branches 11
  • 12. Loops FOR Loop Unlike conventional for loops, for loop in python uses membership operator for iteration. Syntax: for i in range(5): print i * i Output will be 0 1 4 9 16 12 While Loop A while loop repeats a sequence of statements until some condition becomes false. Syntax: x = 5 while x > 0: print (x) x = x - 1 Output will be 5 4 3 2 1
  • 13. Breaking loops Else with loops With loops in python two things comes in mind. breaking and white spaces. we can use keyword break inside any loop and the loop instantly stop iterating when break is executed. Similarly we have continue keyword, when encountered the interpreter simply skips every next steps inside the loop and comes to the next iteration. Whitespace plays a vital role in python. every block that is indented inside the loop is 13 The awesomeness of python is you can use else not only with if but also with loops and exceptions. Every loop in this world is driven by some condition. If that condition is met for the iteration then it goes inside of the loop else it goes inside of else. That makes sense right ? You can simply reduce a bunch of code simply using else with loops. You can use it with both for and while.
  • 14. Branches There is basically only one kind of branch in Python, the 'if' statement. The simplest form of the if statement simple executes a block of code only if a given predicate is true, and skips over it if the predicate is false. if x > 0: print "Positive" if x < 0: print "Negative" 14 "elif" branches onto the if statement. Note, it will stop checking branches as soon as it finds a true predicate, and skip the rest of the if statement. x = -6 if x > 0: print "Positive" elif x == 0: print "Zero" else: print "Negative"
  • 15. Order of operations When more than one operator appears in an expression, the order of evaluation depends on the rules of precedence. For mathematical operators, Python follows mathematical convention. The acronym PEMDAS is a useful way to remember the rules: 1. P : Parenthesis 2. E : Exponential 3. M : Multiplication 4. D : Division 5. A : Addition 6. S : Subtraction 15
  • 16. ThanksStay Tuned for the next part. Enjoy !! 16