Python StartProgram p1
Python StartProgram p1
programming
25+30+601+45
(28+2)*5=150 int
my_variable= 54
x= 25+60-78+45
I-Tuple + Nest
Tuple cant be opearted once define not change
tuple_1=(“djaja”, “mounada”,15,17.1,”Fine”)
index = 0.1.2.3.4
tuple_1[4]=Fine
II-List
List can be oparetaed
a-
l=[14,19.1,”words”,”why”, (15,0.15),[15,17.8,20],20]
index= 0/1/2/3/4/5/6
l[0]=14 , L[6]=20
l[5:7]= [15,17.8,20] , 20
l1=l+[10,”coca”] or l.extend([10,”coca”])
l=[14,19.1,”words”,”why”, (15,0.15),[15,17.8,20],20,10,”coca”]
Change entry
index=0/1/2/3/4/5/6/7/8
a= [”A,B,c,D”] ( 1 elem)
a=[”apple”,15,17.8]
b=a
a[0]= “Love”
b=[’Love”,15,17.8]
III-Dictionary
b-
NB : List =[”index”:”element”] / Dictionary=[”Key”:”Value”]
a- True/false
a=6 / a==7 False
b- If
marks= 40
if(marks>60)
print(“accepted in work”)
c- else like if
marks=45
if(marks>60)
else
d- elif +else
marks=60
if(marks>65)
elif (marks==65)
> “try remote work” + “thank you for your effort of applying to job”
e- Or & And
else
print(“ the album was made in 80s”) > he album was made in the 70s or 90s
II- Loops
range(3)> [0,1,2]
range(10,14) =[10,11,12,13]
I-for loops
squars :
0 1 2 3 4
squares=[”red”,”yellow”,”green”...]
for i in range(0,5):
square[i]=”withe”
square
“red”:0
“yellow”:1
“green”:2
etc...
0 1 2 3 4
squares=[”orange”,”orange”....]
squares=[”orange”, etc......]
new_squares=[]
i=0
while(squares[i]==”ornage” )
i=i+1
For remembre
for x in a
print(x+”s’)
a=[”routes”,”trains”,”voitures”]
c-
for i, x in enumerate(['A','B','C']):
A Basic function
def function(a)
b=a+1
example a-2:
def f1(input)
output= input +1
return output
II - Intern function
0 1 2 3 4
squares=[”red”.”yellow”,”green”,”purple”,”blue”]
example2:
10 15.1 100 32 75
0 1 2 3 4
a=[10....]
B- function sorted
make order
C=[10.7.9.8.100]
or c.sort() >c=[7,8,9,10,100]
C - function Multiply
def mult(x,y)
c=x*y
return c
E= mult(2, “Maroc”)
E= “Maroc”, “Maroc”
D-Function enumerate
stuff 9.8 7 6 2
i 0 1 2 3
def printrating(stuff)
for i, s in enumerate(stuff)
Album 1 ...
for a in a
a=a+1
print([”a”,”b”,”c”]> a1 b1 c1
2- Exception handling
try:
getfile=open(“myfile”,”r”)
getfile.write(“My file for exception handling”)
exceptIO:
A-Type()
type([10,”amine”,15.7] > list
type(1): int
self_color=pink
-class rectangle(object
self_color=blue
C1=Circle(14,”red”)
c1.radius > 14
c1.color > red
If you want change color just type
c1.color=”pink”
lets see
-class=Circle(object):
def add_radius(self,r)
self_radius=self_radius+r
def drawCircle(self):
return(self_redius)
c1=Circle(2,”red)
c1=add_radius(8)
self_radius =self_radius+8
c1> 10, red
car.color=”black”
car.assing.seating.capacity(5)