int() turns into integer, float() for float, str()
Can't turn a numerical int into a float, you need to do this: int(float("3.4))
Arithmetic
print('Addition : ', a + b)print('Subtraction : ', a - b)print('Multiplication : ', a * b)print('Division (float) : ', a / b)print('Division (floor) : ', a // b)print('Modulus : ', a % b)print('Exponent : ', a ** b)
Strings
string="hello world"striing.upper()string.lower()string.capitalize()# First letter capsstring.title()# first letter of each word capsstring.len()# length of the stringstring.count("o")# counts the number of "o" in the centencestring[0]# index of the character in the stringstring[2:]# from index 2 till the endstring[2:15]#between both indexes (not inclusive of the last index)string.find("something")string.repace("something", "something else")# doesn't mutate, only returns."something"in string # boolean if "something" exists in the string"something"notin stringmessage=f"{name} loves the color {color.lower()}!"# use variables within a string
User input
name =input("what's your name")print("Hello {name}")
ducks = ["riri","Fifi","Loulou"]print(ducks[0], list[3])print(ducksst[3:7]pring(ducksst[:])print(ducksist.index("Fifi")print(ducks.count("LouLou")'print(ducks.sort(reverse=True))print(min(ducks))print(max(ducks))ducks.append("Tata")ducks.insert(1, "Tata")ducks[3]="Tata"# Replaces the item at index 3ducks.extend(other_list) # ducks.remove()ducks.pop(2) # ducks.clear() #empties the listdel(ducks) #deletes the whole variablenew_list= ducks[:]new_list= ducks.copy()new_list=list(ducks)
msg="Hello World"
print(msg.split()) # splits each word into a list
print(msg.split("w")) # splits string at each letter w cgreates a list