You are on page 1of 2

PYTHON

HANDLING NUMBERS

n1/n2 = result w/ rests


n1//n2 = result w/o rests
n1%n1 = rest
n1 ** n2 = n1 to the power of n2

HANDLING TEXT

print("text") text

print("te\xt") te
xt

print(r"te\xt") text (prints raw )

len('text') 4

len(var) length of the var

this calculates the length of strings

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

To make a list use the square brackets []

LISTS
Var = [1, 0, 4, 5, 3]

To call a specific string

Var[2] 4

To change a value
Var[position]=new value

To change multiple values


Var[position]=[val1, val2 ]

To add values temporarily


Var + [val1, val2, val3 ]

To add values permanently


Var.append(new values)

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]

You might also like