Python-3
Python-3
Session 3
What will you learn ?
• Introduction • Literals
• Introduction to Data Sets • Conditionals
• Concepts of Variables, Iterations & • Loops
Filtering • Functions
• Data Types • Lists & Tuples
• Sanity of Data • Sets & Dictionaries
• Introduction to Complex Data Types • File Handling
• Hands – On Python • Object Oriented Programming
Print Command in Python
Arrays / Dictionaries
Matrix
Boolean
True / Lists Tuples
False
Variables in Python
1. Simply – It is the name of the area of the hard-disk where a value is stored
2. For Ex. – X=55 ; we can say – 55 is stored in the hard disk and we can call the area
be X
3. Key rules of Variables in Python
• A variable must start with a letter or an underscore( _)
• A variable cannot start with a digit
• A variable can contain only alphanumeric characters and underscores - (A,a,
B,b, C,c 0123456789 ) or ( _)
• Variable names are case sensitive ( Age & AGE ) are different variables
• There is no limit to the length of the variable
• A Variable name cannot contain Spaces
• A variable name cannot be Python Key words
Key words in Python
Python keywords are special reserved words that have specific meanings and purposes and can't be used for
anything but those specific purposes.
Operators in Python
Mathematical & Logical Operators
Operators in Python
Logical
The following table gives the logical operators and the operations that
they correspond to and or are binary operators; not is a unary operator.
Operator Operation
not Negation
and Logical conjunction
or Logical disjunction
Strings in Python
Strings in python are surrounded by either single quotation marks, or double quotation marks and contain all sorts
characters including space (‘ ’).
Indexing in Strings
This is how you will traverse any string and hence giving you some specific way in form of numbers to access a
particular position in the whole string.
Slicing in Strings
<StringName>[ start : end+1 ]
Exercises
# print 5 integers in an ascending order with one number in each line
print(1)
print(2)
print(3)
print(4)
print(5)
#accept your car no as input & print its state code as an output
S=str(input("enter your car no "))
Scode=(S[0:2])
print("the state code is",Scode)
#accept a five-digit number as input and print the sum of its digits as output
num=int(input()
num=input()
D1=int(num[0])
D2=int(num[1])
D3=int(num[2])
D4=int(num[3])
D5=int(num[4])
DSUM=D1+D2+D3+D4+D5
print(DSUM)
Functions in Strings
Functions in Strings
Functions in Strings
Functions in Strings
Exercises
# Accept two positive integers M & N as input. There are two cases to consider
1) If M<N, then Print M as Output
2) If M>=N, subtract N from M and call the difference M1
3) if M1>=N, then subtract N from M1 and call the difference M2
Keep doing this until you reach the value k such that Mk<N
You have to print the value of Mk as output
Ans :---
Resources
• https://drive.google.com/drive/my-drive
• https://www.python.org/
• https://www.python.org/psf/
• http://www.replit.com/
• https://docs.replit.com/tutorials/introduction-to-the-repl-it-ide