Python Code
Expressions
Branches
Loops
Functions
Strings
Expressions
x = 5
y = 3
print (x + y)
String (Expressions)
first = “Hello”
second = “World”
print (first + second)
Branches
value = math.sin(0.33 * pi)
if value < 0:
result = -1
elif value == 0:
result = 0
else:
result = 1
Loops
for x in range(10):
print(“loop”)
for i in range(0, 10, 1):
print(str(i + 1))
sequence = [“first”, “second”,
“third”, “fourth”, “fifth”]
for x in sequence:
print(x)
Functions
def cube(x)
“””returns the cube of a
number
“””
result = x ** 3
return result
value = 2
print(cube(value))
print(cube(3))

Python Basics #1