print("hello")
a = [1,
2,
3]
a
a = [1, # x-axis
2, # y-axis
3 # z-axis
]
a
a = (1, # x-axis
2, # y-axis
3 # z-axis
)
a
a = {1, # first element
2 # second element
}
a
a = {'key1': 'value', #comment
'key2': #comment on the key
'value2' #comment for the value
}
a
def my_func(a, # some comment on a
b, # comment on b
c # comment on c
):
print(a, b, c)
a = 10
b = 20
c = 30
if a > 5 \
and b > 10 \
and c > 20:
print("yes!!")
a = 10
b = 20
c = 30
if a > 5 \
and b > 10 \
and c > 20:
print("yes!!")
a = '''this is
a multi line string'''
print(a)
a = """some items:\n
1. item 1
2. item 2"""
print(a)
def my_func():
a = """a multi-line string
that is actually indented in the second line"""
return a
print(my_func())
def my_func():
a = """a multi-line string
that is actually indented in the second line"""
return a
print(my_func())
def my_func():
"""a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
a multi-line string that is actually indented in the second line
"""
return a
# this is
# a multi-line
# string
a = 2
if a < 3:
print("a < 3")
else:
print("a >=3")
a = 15
if a < 5:
print("a < 5")
else:
if a < 10:
print("5 <= a < 10")
else:
print("a >=10")
a = 15
if a < 5:
print("a < 5")
elif a < 10:
print("5 <= a < 10")
else:
print("a >=10")
# X if (condition) else Y
a = 5
res = 'a < 10' if a < 10 else 'a >=10'
print(res)
a = 15
res = 'a < 10' if a < 10 else 'a >=10'
print(res)
def say_hello():
print("Hello")
def say_world():
print("World")
a = 15
say_hello() if a < 10 else say_world()
@check_country
@IP_correct
@authorize
def calculate_your_savings():
pass
s = [1, 2, 3]
len(s)
from math import sqrt
sqrt(4)
import math
math.exp(1)
def func_1():
print("running func1")
func_1
# invoke or call
func_1()
def func_2(a, b):
return a * b
func_2(3, 2)
func_2(3.3453453453, 9.123121)
func_2("rohan", 5)
func_2("rohan", "shravan")
def func_3(a: int, b: int):
return a * b
func_3('a', 5)
my_func = func_3
my_func(3, 4)
def func_4():
# we are going to be doing something here later on
a = 2
# return None
res = func_4()
print(res)
def func_5():
100/0
100/0
def fn_1():
fn_2()
def fn_2():
print("hello")
fn_1()
def fn_3():
fn_4()
fn_3()
def fn_4():
print("hello")
def func_6(x):
return x**2
func_6 = lambda x: x**2
def func_7(fn, a, b):
return fn(a, b)
def sum(a, b):
return a + b
func_7(sum, 3, 4)
func_7(lambda x, y: x + y, 3, 4)
func_6 = lambda x: x**2
func_6, func_7
i = 0
while i < 5:
print(i)
i += 1
i = 5
while i < 5:
print(i)
i += 1
i = 5
while True:
print(i)
if i >=5:
break
min_length = 2
name = input('Please enter your name:')
while not(len(name) >= min_length and name.isprintable() and name.isalpha()):
name = input('Please enter your name:')
print(f'Hello {name}')
min_length = 2
while True:
name = input('Please enter your name:')
if len(name) >= min_length and name.isprintable() and name.isalpha():
break
print(f'Hello {name}')
a = 0
while a < 10:
a += 1
if a%2:
continue
print(a)
l = [1, 2, 3]
val = 10
found = False
idx = 0
while idx < len(l):
if l[idx] == val:
found = True
break
idx += 1
if not found:
l.append(val)
print(l)
l = [1, 2, 3, 10]
val = 10
idx = 0
while idx < len(l):
if l[idx] == val:
break
idx += 1
else:
l.append(val)
print("I was called")
print(l)
a = 10
b = 1
try:
a / b
except ZeroDivisionError:
print('division by 0')
finally:
print("Finally ALWAYS runs!")
a = 10
b = 0
try:
a / b
except ZeroDivisionError:
print('division by 0')
finally:
print("Finally ALWAYS runs!")
a = 0
b = 2
while a < 3:
print("_________________")
a += 1
b -= 1
try:
res = a / b
except ZeroDivisionError:
print(f'{a}, {b} - division by 0')
res = 0
continue
finally:
print(f'{a}, {b} - I always execute')
print(f'{a} {b} - main loop')
a = 0
b = 2
while a < 3:
print("_________________")
a += 1
b -= 1
try:
res = a / b
except ZeroDivisionError:
print(f'{a}, {b} - division by 0')
res = 0
break
finally:
print(f'{a}, {b} - I always execute')
print(f'{a} {b} - main loop')
a = 0
b = 2
while a < 3:
print("_________________")
a += 1
b -= 1
try:
res = a / b
except ZeroDivisionError:
print(f'{a}, {b} - division by 0')
res = 0
break
finally:
print(f'{a}, {b} - I always execute')
print(f'{a} {b} - main loop')
else:
print('No errors were encountered')
a = 0
b = 5
while a < 3:
print("_________________")
a += 1
b -= 1
try:
res = a / b
except ZeroDivisionError:
print(f'{a}, {b} - division by 0')
res = 0
break
finally:
print(f'{a}, {b} - I always execute')
print(f'{a} {b} - main loop')
else:
print('No errors were encountered')
i = 0
while i < 5:
# some code
print(i)
i += 1
i = None
# for(int i =0; i<5; i++)
for i in "rohan":
print(i)
for i in range(5):
print(i)
for i in [1, 2, 3, 'rohan']:
print(i)
for x in [(1,2), (2, 3), (3, 4)]:
print(x)
for x, y in [(1,2), (2, 3), (3, 4)]:
print(x, y)
for i in range(5):
if i == 3:
continue
print(i)
for i in range(5):
if i == 3:
break
print(i)
for i in range(1, 5):
print(i)
if i % 7 == 0:
print('multiple of 7 found')
break
else:
print('No multiples of 7 found')
for i in range(1, 8):
print(i)
if i % 7 == 0:
print('multiple of 7 found')
break
else:
print('No multiples of 7 found')
for i in range(5):
print("_____________")
try:
10 / (i - 3)
except ZeroDivisionError:
print("divided by 0")
continue
finally:
print("always runs")
print(i)
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
r1 = Rectangle(10, 20)
r2 = Rectangle(3, 5)
r1.width
class Rectangle:
def __init__(rohan, width, height):
rohan.width = width
rohan.height = height
r1 = Rectangle(10, 20)
r2 = Rectangle(3, 5)
r1.width