Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Python 101 tutorial :

String methodes (functions):

len(name) : for the length of the string


name.find("o") : to find a caractere
name.capitalize : Maj for the first letter
name.upper / name.lower
name.isdigit : digit ( 0 1 2 ...)
name.isalpha : alpha ( letters a b c .. z ) Nb: space is not alpha
name.count("o") : to count how many appearances for a letter
name.replace("o","a") : which means replace o with an a
print(name*3) : print name 3 times

---------------------------------------

math functions : ( add " import math " )

round(pi)
math.ceil(pi) : rounding up
math.floot(pi) : rounding down
abs(pi) : the absolute value
pow(pi.n)
math.sqrt(144)
max(x,y,z)
min(x,y,z)

----------------------------------------

string slicing : using indexing[] or slice()

indexing[] :
name = "Hadj Ali Mohamed"

[start:stop:step]

"Hadj" = name[0,4] / name[:4] / name[:4:1]

"Mohamed" = name[8:] # name[8:end]

to reverse name : name[::-1]

slice() :

s = slice(start,end) # end u can use negative indexing


print(name[s])
------------------------------------

if statements :

if a > b:
print("higher")
elif a < b:
print("lower")
else:
print("equal")

logical operators : or and not


-------------------------------------
while loop :

name = ""
while len(name) == 0 :
name = input("enter your name pls: ")
--------------------------------------

for loop : for i in range(star,end,step)


# it can iterate in any thing considered iterable

for i in range(5):
print(i) #output : 0 1 2 3 4
print(i+1) #output : 1 2 3 4 5

for i in range( 5 , 10 ):
print(i) #output : 5 6 7 8 9
to fix it add 10+1

for i in "Mohamed":
print(i) # output : M o h a m e d

cool program :
import time

for seconds in range(10,0,-1):


print(i)
time.sleep(1) # after each itiration hold for 1s
print("Happy ramadan")

nested loop :
for i in range(rows):
for j in range(columns):
print(*,end="")
print() # this will auto print new line

-----------------------------------
break continue pass:

break : used to terminate the loop entirely


continue : skips to the next iteration of the loop
pass : does nothing , acts as a placeholder

You might also like