Knowledge organisersData Types and Casting
Correct invalid type usage.
A TypeError happens when you use an operator on incompatible types, such as adding a string and an integer. The fix is to cast one value to match the other.
"5" + 3 causes TypeError — can't add str and intint("5") + 3 or "5" + str(3)input() always returns str — cast before mathsage = input("Age: ") # returns "15" (str)
# age + 1 ← TypeError!
age = int(age)
print(age + 1) # 16