0% found this document useful (0 votes)
26 views10 pages

Quick Recap Python 1

Uploaded by

najwa dirar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views10 pages

Quick Recap Python 1

Uploaded by

najwa dirar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

quick-recap-python-1

May 24, 2024

[1]: print("Notre message")

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
"""

[9]: '\nhello\nworld\nun commentaire\nmultilignbe\n'

[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)

Orange Orange Orange

2
[29]: liste = [1, 2, 4]
x, y, z = liste
print(x, y, z)

1 2 4

[36]: # Variable Globale & Variable local

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)

6.0 1.0 1.0

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

[51]: a = ''' Paragraphe multo


ligne
'''
print(a)

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")

Yes " M,ta" is present

[69]: Chaine = "Hello, World!"


print(Chaine)

Hello, World!

[70]: print(len(Chaine))

13

[71]: print(Chaine[7:])

World!

[73]: print(Chaine[:5]) # de 0 vers 5

Hello

[74]: print(Chaine[7:13]) # de 7 vers 12

World!

[80]: print(Chaine[-6:])

World!

[81]: print(Chaine[:-8])

Hello

[95]: A = " taoufik, Amzil "


print(A)

taoufik, Amzil

[86]: # Upper Case


print(A.upper())

TAOUFIK

[87]: # Lower Case


print(A.lower())

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

[97]: print(A.replace("f", "k"))

taoukik, Amzil

[102]: A = "Bonjour, Tout, le, monde"


print(A)

Bonjour, Tout, le, monde

[100]: print(A.split()) # by default " "

['Bonjour', 'Tout', 'le', 'monde']

[103]: print(A.split(","))

['Bonjour', ' Tout', ' le', ' monde']

[104]: A = "Taoufik"
B = "Amzil"

[106]: print(A + " " + B)

Taoufik Amzil

[114]: a = 20
z = 12
b = "ans"

[116]: print(f"J'ai {a} " + b + f" {z}")

J'ai 20 ans 12

[117]: print(f" La somme de 2 et 5 est : {2 + 5}")

La somme de 2 et 5 est : 7

6
[123]: txt = "We are the so_called \'vikings\' from the north."
print(txt)

We are the so_called 'vikings' from the north.

[131]: print(txt.find("from"))

31

[137]: liste = ["Hello", "World", "!"]

x = " ".join(liste)
print(x)

Hello World !

[138]: print(10 > 9)

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]: ==
!=
>
<
>=
<=

Cell In[154], line 1


==
^
SyntaxError: invalid syntax

[155]: and &


or
not

Cell In[155], line 1


and &
^
SyntaxError: invalid syntax

[157]: x = 0
x < 5 and x > 10

[157]: False

[158]: x < 5 or x > 10

[158]: True

8
[159]: not(x < 5 and x > 10)

[159]: True

[160]: is
is not

Cell In[160], line 1


is
^
SyntaxError: invalid syntax

[162]: x = " "


y = " "

x is y

[162]: True

[164]: x = " "


y = " "

x is not y

[164]: True

[165]: in
not in

Cell In[165], line 1


in
^
SyntaxError: invalid syntax

[166]: x = "hello"
y = "hello world"

x in y

[166]: True

[168]: x = "hel"
y = "hello world"

9
x not in y

[168]: False

[169]: & : and


| : or
^ : XOR
not : ~

Cell In[169], line 1


& : and
^
SyntaxError: invalid syntax

[170]: print( 6 + 3 - 6 + 2 / 4 )

3.5

[171]: print( ((6 + 3) - (6 + 2)) / 4 )

0.25

[ ]:

10

You might also like