Master Python Branching, Slicing, and Loops Simplified For All Learners
Master Python Branching, Slicing, and Loops Simplified For All Learners
Lecture 4 & 5
1
RECAP Lecture 3
q OBJECTS
q EXPRESIONS
q OPERATORS ON ints and floats
q BINDING VARIABLES AND VALUES
q CHANGING BINDINGS
q STRINGS
OBJECTS
EXPRESIONS
OPERATORS ON ints and floats
BINDING VARIABLES AND VALUES
CHANGING BINDINGS
STRINGS
hi = "hello there"
name = "batch23 students"
action="Wake up"
greet = hi + name
print(greet)
import keyword
print (keyword.kwlist)
PYTHON ALLOWS MULTIPLE ASSIGNMENT
• x, y = 2, 3
• binds x to 2 and y to 3
• All of the expressions on the right-hand side
of the assignment are evaluated before any
bindings are changed
• Can we swap the bindings of 2 variables ????
Python allows multiple assignment
Output:
Even
Done with conditional
NESTED CONDITION AND ELIF
#Example nested if condition and elif and comments
#----- Initializing variables-------
x=3
y=2
#----------First condition----------------
if x < y:
print("you win")
if x==3:
print ("100 rps")
else:
print ("10 rps")
#-----------Nested condition ends here ---
#-----------Second Condition-------------
elif x == y:
print("second condition")
#---------------second condition ends here---
#-----------third Condition-------------
elif x > y:
print("third condition")
#---------------second condition ends here---
else:
print("you lose")
# -----------First condition ends here------
print("multiple conditions")
COMPARISON OPERATORS
LOGICAL OPERATORS ON bools
LENGTH AND INDEXING
• The length of a string can be found using the len function. For example, the
• value of len('abc') is 3.