KEMBAR78
Python Keywords | PDF | Computer Engineering | Programming Paradigms
0% found this document useful (0 votes)
45 views7 pages

Python Keywords

This document provides a cheat sheet on Python keywords including if/elif/else for conditional execution, for/while for loops, in to check if an element is in a sequence, is to check if objects point to the same reference, None as the empty value constant, lambda for anonymous functions, and return to terminate a function and pass the result. It includes code examples for each keyword.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views7 pages

Python Keywords

This document provides a cheat sheet on Python keywords including if/elif/else for conditional execution, for/while for loops, in to check if an element is in a sequence, is to check if objects point to the same reference, None as the empty value constant, lambda for anonymous functions, and return to terminate a function and pass the result. It includes code examples for each keyword.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

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

You might also like