Basic
len = length
phrase.index
phrase.replace
modulus operator % - leftover after divide operation
input("prompt")
Lists
[] square brackets = list
[1:3] range elemets i list
.extend() - adds lists together
.append() -adds an item to the end
.insert() - (1, item) adds item to position 1
.remove() - removes particular item
.clear - clears the whole list
.pop - removes last element of list
.index - gives the index of item
.count - how many times a particular value is in the list
.sort - ascending order
.reverse
.copy
Tuple
container for different values
can't change
xxx = ()
Functions
def xxx(parameter):
lowercase names
RETURN STATEMENT
return
if xxx:
if xxx or yyy: one must be true
if xxx and yyy: both must be true
elif - else if
elif xxx and not (yyy): - will change yyy to oposite
Operators
!= not equal
== equal
= greater or equal to
2**3 = 2^3
Types
float(input("Enter number)) - converts to float
str()-konvertuje na string
abs() - absolutna value
pow(cislo, exponent)
round - rounding value
Math
from math import*
floor - chops off decimal point
ceil - round value up
sqrt - shows square root
Dictionaries
xxx = {yyy:zzz,} yyy asociates to zzz
open("employees.txt","r")
r read, w write, a append, r+ read and write
Loops
while
i+=1 - i + 1
and not() - one OR the other option
For loop
for index in range(3):
index = 0, 1, 2, - for every itteration
Nested for loop
for row in number_grid:
for col in row:
print (col)
COMMENTS - use hashtags
Resources: