Quick Recap Python 1
Quick Recap Python 1
Notre message
int 0 1 float 1.5 2.1 char “c” “1” “T” String “Chaine caracteres” boolean True False
[3]: var = 12
[4]: print(var)
12
[5]: print(2 + 2)
[9]: # Monoligne
"""
hello
world
un commentaire
multilignbe
"""
[11]: x = 5
print(type(x))
y = "nom"
print(type(y))
x = "Salary"
print(type(x))
<class 'int'>
<class 'str'>
<class 'str'>
1
[14]: # Casting
x = 5
print(type(x))
print(x)
x = float(x)
print(type(x))
print(x)
<class 'int'>
5
<class 'float'>
5.0
[17]: x = "chaine1"
y = "chaine2"
z = x + " " + y
print(z)
chaine1 chaine2
[19]: a = 5
A = 7
a != A
False
[25]: variable = 0
_variable = 0
# 2variable = 0
# (A-Z et a-z, 0 - 9 , _ )
[27]: X = 1
Y = 2
Z = 3
x, y, z = 1, 2, 3
print(x, y, z)
1 2 3
[28]: x = y = z = "Orange"
print(x, y, z)
2
[29]: liste = [1, 2, 4]
x, y, z = liste
print(x, y, z)
1 2 4
def myfucntion():
global x
x = "Fantastic"
print(x)
print(x)
myfucntion()
Fantastic
Fantastic
[37]: int()
float()
str()
[37]: ''
[44]: x = 6.0
y = "1"
z = True
print(x, y, z)
6.0 1 True
[40]: x = int(x)
y = int(y)
z = int(z)
[41]: print(x, y, z)
6 1 1
[45]: x = float(x)
y = float(y)
z = float(z)
print(x, y, z)
3
[46]: x = 6.0
y = "1"
z = True
print(x, y, z)
6.0 1 True
[48]: x = str(x)
print(x)
print(type(x))
6.0
<class 'str'>
[56]: a = "Taoufik"
print(a)
Taoufik
Paragraphe multo
ligne
[54]: print(a[0])
[58]: for i in a:
print(i)
T
a
o
u
f
i
k
[59]: print(len(a))
4
[67]: if "To" not in a :
print("Yes \" M,ta\" is present")
Hello, World!
[70]: print(len(Chaine))
13
[71]: print(Chaine[7:])
World!
Hello
World!
[80]: print(Chaine[-6:])
World!
[81]: print(Chaine[:-8])
Hello
taoufik, Amzil
TAOUFIK
taoufik
5
[90]: # Remove whitespaces : rstrip - lstrip - strip
print(A.rstrip())
taoufik, Amzil
[94]: print(A.lstrip())
taoufik, Amzil
[96]: print(A.strip())
taoufik, Amzil
taoukik, Amzil
[103]: print(A.split(","))
[104]: A = "Taoufik"
B = "Amzil"
Taoufik Amzil
[114]: a = 20
z = 12
b = "ans"
J'ai 20 ans 12
La somme de 2 et 5 est : 7
6
[123]: txt = "We are the so_called \'vikings\' from the north."
print(txt)
[131]: print(txt.find("from"))
31
x = " ".join(liste)
print(x)
Hello World !
True
[139]: print(10 == 9)
False
[140]: print(bool("Hello"))
True
[141]: print(bool(16))
True
[142]: print(bool(0))
False
[143]: print("False")
False
[144]: print(10 % 2)
[146]: print(10 / 2)
5.0
[147]: print(10 ** 2)
7
100
[151]: x = 1
print(x)
[152]: x += 1
[153]: print(x)
[154]: ==
!=
>
<
>=
<=
[157]: x = 0
x < 5 and x > 10
[157]: False
[158]: True
8
[159]: not(x < 5 and x > 10)
[159]: True
[160]: is
is not
x is y
[162]: True
x is not y
[164]: True
[165]: in
not in
[166]: x = "hello"
y = "hello world"
x in y
[166]: True
[168]: x = "hel"
y = "hello world"
9
x not in y
[168]: False
[170]: print( 6 + 3 - 6 + 2 / 4 )
3.5
0.25
[ ]:
10