integer: int=42# We can use type hints, Python interpreter tends do ignore it entirelyanother_integer=42_000_000# We can safely ignore the _, it's just for visual conveniencefloating: float=.42# We can be lazy and omit the 0 before 0.42string: str="This is a string"another_string: str='This is another string'f_string: str=f"4! equals to {4*3*2*1}"boolean: bool=Trueanother_bollean: bool=False
Functions
deffunc1() ->None:
print("Do something")
deffunc2() ->str:
return"Return something"deffunc3(a: int, b: int) ->None:
print(f"Inside: {a} + {b} => {a+b}")
deffunc4(a: int, b: int) ->int:
print(f"Inside: {a} + {b} => {a+b}")
returna+bdeffunc5(a: int, b: int) ->int:
returna**bdeffunc6(*args, times=1) ->int:
returnsum([argforarginargs]) *timesprint(f"func1: {func1()}")
# We do something inside the function and implicitly return Noneprint(f"func2: {func2()}")
# We return something to the callerprint(f"func3: {func3(2, 5)}")
# We do something inside with the given params but we return implicitly Noneprint(f"func4: {func4(3, 39)}")
# We do something inside with the given param and return some relevant value to the callerprint(f"func5: {func5(2, 10)}")
print(
f"func5: {func5(b=10, a=2)}"
) # we can change the param order provided by the names# And we can pass an undefined list of unnamed argumentsprint(f"func6: {func6(1, 2, 3)}")
print(f"func6: {func6(1, 2, 3, 4, 5, 6)}")
print(f"func6: {func6(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)}")
print(f"func6: {func6(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, times=2)}")