print("Goodby World")Goodby World
x = 11 #Without type specification
y: int = 11 #With type specificationprint(x)
print(y)11
11
nev: str = "WaveG"
print(nev)
print(f"First character is: {nev[1]}")
print(f"Reversed: {nev[::-1]}")WaveG
First character is: a
Reversed: GevaW
print(f"There are {y} monkeys")There are 11 monkeys
not and not !or and not |and and not &True, as False)
type()Is returns True if both variables are the same
objecta = True
b = False
print(a and b)
print(a or b)
print(a and b)
print(a is b)
x = 1
x += 12
print(x)False
True
False
False
13
This is the part where the most controversial thing come in python. The indentation There aren't any curly brackets. The only thing that says wich line is in the cycle is the indentation, wich is 4 space long
for i in range(12):
print(i)0
1
2
3
4
5
6
7
8
9
10
11
list = [1, 2, 3, 4, 5] #It's like an array we will se it later
for number in list:
print(number)1
2
3
4
5
list = [] #It's like an array we will se it later
for number in list:
print(number)
else:
print("empty list")empty list
i = 1
while i < 11:
print(i)
i += 11
2
3
4
5
6
7
8
9
10
list = [1, 2, 3, 4]
for number in list: #Interating through the list
print(number)
print(list)
print(list[1]) #2nd element of the list
print(list[-1]) #last element of the list
print(list[1:-1]) #2nd to last element of the list1
2
3
4
[1, 2, 3, 4]
2
4
[2, 3]
def square1(num):
return num**2
def square(num: int) -> int:
return num**2
print(square1(2))
print(square(4))4
16
func = square
func(6)36