Professional Documents
Culture Documents
Python
Python
HANDLING NUMBERS
HANDLING TEXT
print("text") text
print("te\xt") te
xt
len('text') 4
VARIABLES
Var 1 = "variable"
Var1 +"text" 'variable text'
Var1 * 3 'variable variable variable'
Var = "tuna"
Var[0] 'T'
Var[1] 'U'
Var[-2] 'n'
Var[1:3] 'un'
Var[:3] 'tun'
Var[2:] 'na'
To access a specific letter or number in a string
LISTS
Var = [1, 0, 4, 5, 3]
Var[2] 4
To change a value
Var[position]=new value
IF STATEMENT
If,elif(else if), else always use ":"
if var == value1 :
run this command
elif var == value2: (if the first statement isnt true)
run this command
else: (if non on the above is true then run this command)
run this command
FOR
List = [a list]
for x in list[:2]:
run this code
x is a new variable takes place of each item in the list
you can use the print commands print(x) ,print(len(x))
you can take parts of the list list[:2]