Module 1: Python basics · 10 min
Working with numbers and text
a = 7
b = 2
print(a + b) # 9
print(a / b) # 3.5 (normal division)
print(a // b) # 3 (whole-number division)
print(a % b) # 1 (remainder)
print(a ** b) # 49 (power)
Text can be joined, measured and changed. An f-string lets you put values inside text.
city = "Lahore"
print(city.upper()) # LAHORE
print(len(city)) # 6
print(city[0]) # L (counting starts at 0)
temp = 31.5
print(f"It is {temp} degrees in {city}")
Use input() to ask the user for text. It always returns text, so convert it with int() or float() if you need a number.
age_text = input("Your age? ")
age = int(age_text)
print("Next year you will be", age + 1)