PYTH
PYTHON
HON
KEYWORDS
Cheat Sheet part 2
Follow On www.1stepgrow.com
P
Keywords
Y
T
if, elif, else
Conditional program execution: program
starts with
“if” branch, tries the “elif” branches, and
H
finishes with
“else” branch (until one branch evaluates
to True).
Code example
O
x = int(input("your value: "))
if x > 3: print("Big")
elif x == 3: print("Medium")
else: print("Small")
Follow On www.1stepgrow.com
P
Y
T
for, while
# For loop declaration
for i in [0,1,2]:
print(i)
H
Code example
# While loop - same semantics
j = 0
while j < 3:
O
print(j)
j = j + 1
Follow On www.1stepgrow.com
P
in
Y
T
Checks whether element is in sequence
Code example
42 in [2, 39, 42] # True
H
is
Checks whether both elements point to
the same object
O
Code example
y = x = 3
x is y # True
[3] is [3] # False
Follow On www.1stepgrow.com
P
None
Y
T
Empty value constant
Code example
def f():
x = 2
H
f() is None # True
lambda
Function with no name (anonymous
O
function)
Code example
(lambda x: x + 3)(3) # returns 6
Follow On www.1stepgrow.com
P
return
Y
T
Terminates execution of the function and
passes the
flow of execution to the caller. An
H
optional value after
the return keyword specifies the function
result.
Code example
O
def incrementor(x):
return x + 1
incrementor(4) # returns 5
Follow On www.1stepgrow.com
P
Y
IS THIS
INFORMATIO T
N HELPFULL?
Don't forget to like, share, and save this post if you
found it useful!
H
Follow On www.1stepgrow.com
O