Introduction to Python
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Agenda
● Jupyter Notebook
● Variables
● Data Types
○ Fundamental
kodaliyoganand1997@[Link] Data Types
VGNQ9IQTEJ
● Functions in Python – print()
● Operators
● Python Flow Control
● Pseudocodes
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Jupyter Environment
● The Jupyter Notebook is an open-source
web-based development application that
allows you to create documents that can
kodaliyoganand1997@[Link] have code, equations, visualizations
VGNQ9IQTEJ and narrative text.
● Mainly used for data cleaning and Data
transformation, statistical modeling,
data visualization, machine learning,
deep learning and much more.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Jupyter Environment
● You can use Jupyter for over 40
programming languages. Within the
data science community, mainly used
for Python, R, Julia and Scala.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
● You can also use Jupyter with big data
tools, like Apache Spark from Python
(known as PySpark), R and Scala.
You can explore big data with pandas,
scikit-learn, ggplot2, TensorFlow and
more.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Jupyter Editor
Notebook name. Click
here to change the name
of the notebook
kodaliyoganand1997@[Link] Menu bar
VGNQ9IQTEJ
Toolbar
Code cell. Write your
code here
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Commenting code
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
#
Code commenting is required in order to describe the purpose of the code. This is
not only a good practice but also a mandatory practice in most organizations.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Variables
● Variables are containers that store data. Python has no command for
declaring variable
● You simply assign a value to a variable to create it
kodaliyoganand1997@[Link]
● You use = to assign a value to a variable
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Print variables with texts
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Reassign variable
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Multiple variables assignment with same value
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Multiple variables assignment with different values
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Python data types
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
We learn the following in our session today
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Create integer & string variables
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Create float & boolean variables
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Checking data types with type() function
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Data type conversion
Python allows to convert one data type to another
Implicit Conversion: Conversion Type Conversion
done by Python interpreter with
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
programmer’s intervention
Implicit Conversion Explicit Conversion
Explicit Conversion: Conversion
that is user-defined that forces an
expression to be of specific data type
Arithmetic
Casting Operation
Operation
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Implicit conversion
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Explicit conversion is required when you have mixed data types.
Numeric Data type
kodaliyoganand1997@[Link] String Data type
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Explicit conversion
String Data type. Needs to be
converted to integer type before
adding to another numeric
kodaliyoganand1997@[Link] variable
VGNQ9IQTEJ
Explicit type conversion
of string to integer type
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Type casting
Type Casting
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
int() float() str() bool()
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Type casting
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Functions in Python
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
What is a function?
Name of the Input
● A function is a block of code that runs when called function, sum() parameters
● A function has a
kodaliyoganand1997@[Link] name. You call the function by its
VGNQ9IQTEJname
● A function can take input(s), known as input
parameters
● A function can return data as a result
Return value of
the function
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The print() Function
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The print() in python
Words or sentences separated by a comma
within a print() function get concatenated
when printed.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The print() in python
The sep is an optional parameter. When
output is printed, each word is separated
by ^^^ characters
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
print(‘\n’) gives a new blank line
The backslash “\” is known as escape character. It is used in representing certain
whitespaces.
For example ‘\t’ is a tab
This fileand ‘\n’for
is meant ispersonal
a new use
line.
by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Invalid use of opening and closing quotes
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Print with concatenation
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
You cannot concatenate string & number
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
That’s wrong because adding numbers to strings doesn’t make any sense. You
need to explicitly convert the number to string first, in order to join them together.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Concatenating with type casting
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
Explicit conversion of a number
to string with str() function.
We learn more such type
conversions in our upcoming
sessions
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Python Operators
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Python operators
Python
Operators
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
Arithmetic Relational Logical Special
Operators Operators Operators Operators
Bitwise Assignment
Operators Operators
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Addition
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Addition
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
Note that 22 is a string here because it
has been put within the quotes.
Here two strings are getting concatenated.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Subtraction
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Subtraction
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
When two strings are added, the operator basically concatenates the two strings.
Subtracting two strings does not make any sense.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Multiplication
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Multiplication
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Multiplication
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Division
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Division
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Get quotient
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Get remainder
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Arithmetic operators: Get square & power output
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Runtime variable
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Runtime variable
The default return type of a runtime variable is string.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Runtime variable
The default return type of a runtime variable is string. So in order to use
the entered value for computation we convert the values to integer.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Relational operators
Relational operators are used to compare 2 values and take certain
decisions based on the outcome (outcome is is a boolean value)
kodaliyoganand1997@[Link]
< is less than
VGNQ9IQTEJ
<= is less than & equal to
> is greater than
>= is greater than & equal to
== is equal to
!= is not equal to
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Relational operators
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Logical operators
Logical operators in Python are used for conditional statements are either
True or False
kodaliyoganand1997@[Link]
AND Returns True if both the operands are True
VGNQ9IQTEJ
OR Returns True if either of the operands are True
NOT Returns True if the operand is False
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
AND operator
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
OR operator
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
NOT operator
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Membership operators
Membership operators tests whether a value is a member of a sequence. The
sequence may be a list, a string, a tuple, or a dictionary.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
The ‘in’ operator is used to check if a value exists in any sequence object or not.
in For example, if 2 exists in a list, say [4, 5, 7, 2]. This evaluates to True if it finds a
value in the specified sequence object. Otherwise it returns a False.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Membership operators
kodaliyoganand1997@[Link]
VGNQ9IQTEJnot in A ‘not in’ works in an opposite way to an ‘in’ operator. A ‘not in’ evaluates to True if
a value is not found in the specified sequence object. Else it returns a False.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Membership operators
Example:
in operator: not in operator:
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Some bitwise operators
Python Bitwise Operators take one to two operands, and operates on it/them bit by
bit, instead of whole
kodaliyoganand1997@[Link]
VGNQ9IQTEJ & The binary and (&) takes two values and performs an AND-ing on each pair of
(Bitwise bits.
and)
Compared to &, this one returns 1 even if one of the two corresponding bits from
| the two operands is 1.
(Bitwise or)
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The truth tables
& |
(Bitwise and) (Bitwise or)
kodaliyoganand1997@[Link] Value Value Value | Value
Value Value Value
VGNQ9IQTEJ & Value
True True True True True True
True False False True False True
False True False False True True
False False False False False False
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Some bitwise operators
Example:
& operator: | operator:
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
(9 % 3 == 0) & (9 % 5 == 0) (9 % 3 == 0) | (9 % 5 == 0)
Implies True & False Implies True | False
This results in Fasle. This results in True.
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
More assignment operators
The assignment operators are used to store data into a variable.
a += b is same as a = a + b
kodaliyoganand1997@[Link]
VGNQ9IQTEJ a *= b is same as a = a * b
a /= b is same as a = a / b
a %= b is same as a = a % b
a **= b is same as a = a ** b
a //= b is same as a = a // b
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Data slicing
The basic syntax for a slice is square brackets with colons and integers
inside "[Link]".
myStr[start : stop : step]
kodaliyoganand1997@[Link]
myStr[ : stop] # By using one colon and leaving the first argument blank
VGNQ9IQTEJ
we automatically start at index 0, stepping by 1
myStr[start : ] # By using one colon and leaving the last argument blank
we automatically go to the end, stepping by 1
myStr[ : : step] # by using two colons and leaving the first two arguments
blank we start at index 0, go to the end and step by 1
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Data slicing
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
‘:’ is used to specify range of the
sequence to be sliced
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Data slicing
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Data slicing
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
String Handling
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
String Handling
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
Returns a concatenated string where
each character of s1 is separated with
sep string which is ‘-’
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
String Handling
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
Returns a list containing
elements as strings separated
by the space character
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
String Handling
Returns a copy of the string with both
leading and trailing characters removed
(based on the string argument passed)
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Python Flow Control
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Python Flow Control
Any program has a flow. The flow is the order in which the program’s code
executes. The control flow of a Python program is controlled by:
kodaliyoganand1997@[Link]
VGNQ9IQTEJ 1. Conditional Statements
2. Loops
3. Function Calls
We cover the basics of conditional statements and loops in today’s session
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The if-statement
Sometimes we want to execute a code only if a certain condition is true.
The if statement is used in Python for decision making. An "if statement" is
written by using the if keyword.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
Syntax:
if test expression:
statement(s)
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The if-statement
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The if-else statement
The ‘if..else’ statement evaluates a test expression and will execute the code
that is part of the ‘if’ expression if the test expression True.
If the test expression is False, the code that is part of the ‘else’ expression is
executed. Note the indentation that is used to separate the ‘if’ and ‘else’ blocks.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
Syntax:
if test expression:
Body of if
else:
Body of else
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The if-else statement
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The while Loop
Loops are used to repeat the execution of a specific block of code.
The ‘while loop’ in Python is used to iterate over a block of code as long as the
test expression holds true.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
We generally use this loop when the number of times to iterate is not known to
us beforehand.
Syntax:
while test_expression:
Body of while
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The while Loop
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The for Loop
The ‘for loop’ in Python is used to iterate over the items of a sequence object like
list, tuple, string and other iterable objects.
The iteration continues until we reach the last item in the sequence object. Note
the indentation that is used in a ‘for loop’ to separate the rest of the code from the
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
‘for loop’ syntax
Syntax:
for i in sequence:
Body of for
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
The for Loop
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Pseudocode
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
What is Pseudocode?
kodaliyoganand1997@[Link]
Pseudocode is a step-by-step written outline of your code that you can
VGNQ9IQTEJ
gradually transcribe into programming language
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Example: Pseudocode
Find the sum of 5 numbers:
1. Set sum=0, count=0
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
2. Enter the number
3. Add number to sum and store it back to
sum
4. Increment count by 1
5. If count < 5, go to step 2 else print total
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
Write pseudocode to calculate sum & average of 10 numbers that you
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
input
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
There exists a word “Pythonic”? What does it mean?
There are many ways to accomplish the same task in Python, but
there is usually one preferred way to do it. This preferred way is
called "pythonic."
kodaliyoganand1997@[Link]
VGNQ9IQTEJ
Read The Hitchhiker’s Guide to Python ([Link]
[Link]/writing/style/).
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.
kodaliyoganand1997@[Link]
VGNQ9IQTEJ Thank You
This file is meant for personal use by kodaliyoganand1997@[Link] only.
SharingProprietary
or publishing the
content. © Great contents
Learning. in partUnauthorized
All Rights Reserved. or full is useliable forprohibited.
or distribution legal action.