1 Introduction To Python
1 Introduction To Python
• Please log in 10 mins before the class starts and check your internet connection to avoid any network issues during the LIVE
session
• All participants will be on mute, by default, to avoid any background noise. However, you will be unmuted by instructor if
required. Please use the “Questions” tab on your webinar tool to interact with the instructor at any point during the class
• Feel free to ask and answer questions to make your learning interactive. Instructor will address your queries at the end of
on-going topic
• Raise a ticket through your LMS in case of any queries. Our dedicated support team is available 24 x 7 for your assistance
• Your feedback is very much appreciated. Please share feedback after each class, which will help us enhance your learning
experience
▪ Need of Programming
▪ Python Interpreter
John
John
He creates a set of folders to organize these materials by course, lesson and type of file
Creating these
folders take a Physics
lot of time
John wants something
to automate this task,
and save a lot of time
Chemistry
Annie
Annie
John
Annie
Keeps track of historic data and analyses it Improve customized your existing system
Seat allocation in engineering college: Go to the counseling Have lots of time to research the colleges, decide upon the
center far away from your town, wait for hours together for your colleges and branches, review them multiple people and submit
turn, but make the decision of which college and branch to it online with peace of mind
choose in less than 5 minutes
Python
Portable
Supported by many platforms like Linux, Windows, FreeBSD, Macintosh,
Solaris, BeOS, OS/390, PlayStation, Windows CE, etc.
Extensible
Python code can invoke C and C++ libraries, can be called from and C++ programs,
can integrate with Java and .NET components
▪ Example: help(‘for’)
No braces to indicate Blocks of code are The number of spaces Leading whitespace at
blocks of code for class denoted by line in the indentation is the beginning of a logical
and function indentation, which is variable, but all line is used to compute
definitions or flow rigidly enforced statements within the the indentation level of
control block must be the line, which in turn, is
indented the same used to determine the
amount grouping of statements
print(‘Hello World’)
print("Welcome to Edureka")
▪ An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters,
underscores and digits (0 to 9)
▪ Python does not allow special characters such as @, $ and % within identifiers
Starting an identifier with two leading If the identifier also ends with two
underscores indicates a strongly private trailing underscores, the identifier is a
identifier language-defined special name
A=16 Memory
A = 16
B = 20 Memory
B=20
C = ‘edureka’
C= ‘edureka’ Memory
A=10
B='edureka!'
print(A,B)
Output
Strings Dictionaries
Numbers Tuples
Strings
Strings
Integer
Numeric
A=10 Float
Strings B=10.65
C=10+6j
Complex
print(A,B,C)
Tuples
Output
print(A)
print(B)
Tuples
Output
print(A)
Tuples
Output
Lists Sets
Dictionaries
Dictionaries
Lists are enclosed within
A=[1,2,3.15,'edureka!’]
square brackets
print(A)
Sets
Output
Keys
Dictionaries
A={'Age':24, 'Name':'John'}
print(A)
Values
Sets
Output
Every element in a
Set has to be unique
Dictionaries
A={1,2,3,3}
print(A)
Sets
Output – Notice that 3
has appeared only once
Arithmetic
Addition a+b
Assignment
Subtraction a–b
Comparison
Multiplication a*b
Arithmetic
Assigns value from right to left a=b
Assignment
a=a+b a+=b
Comparison
a=a-b a-= b
Logical
a = a*b a*=b
Bitwise
a = a/b a /= b
Identity
a = a**b a** = b
Membership a//=b
a=a//b
Arithmetic
Equal To a == b
Assignment
Not Equal To
Comparison a != b
Arithmetic
Comparison
a or b Returns b, if b is False, a otherwise
Logical
Bitwise
not a Returns True, if a is False, False otherwise
Identity
Membership
Arithmetic
Binary OR a|b
Comparison
Logical
Binary XOR a^b
Arithmetic
Evaluates to TRUE, if the variables on either side of the
is
Assignment operator point to the same object and FALSE otherwise
Comparison
Identity
Membership
Arithmetic
Assignment
in Evaluates to TRUE, if it finds a variable in the specified
Comparison sequence and FALSE otherwise
Logical
Membership
If condition is
TRUE
Conditional Code
If Elif Else
Example:
Syntax:
X=10
Y=12
if(X<Y):
print('X is less than Y')
elif(X>Y):
print('X is greater than Y')
else:
print('X and Y are equal')
Condition
If condition is
false
While For Nested
Syntax:
Condition
count=0
while(count<5): Conditional
print(count) Code
count=count+1
print("Good bye!")
fruits=['Banana','Apple','Grapes']
count=1
for i in range(10):
print(str(i)*i)
For loop inside
for j in range(0,i): a For loop
count=count+1
Output
▪ The brackets which follow main are used for this purpose
▪ . argv refers to the number of arguments passed, and argv[] is a pointer array which points to
each argument which is passed to main
▪ The Python sys module provides access to any command-line arguments via the sys.argv. This serves two
purposes :