The print() function is used to display output on the screen.
print("Hello, world!")
print(10)
print(3.14)
This will output:
Hello, world!
10
3.14
You can print multiple values by separating them with commas.
name = "Alex"
age = 25
print(name, age)
Output:
Alex 25
The input() function allows the user to enter data.
The input is always returned as a string.
name = input("Enter your name: ")
print("Hello", name)
Since input() returns a string, you must convert it
when working with numbers.
age = int(input("Enter your age: "))
print("Next year you will be", age + 1)
f-strings allow you to easily insert variables into text.
name = "Maria"
score = 90
print(f"{name} scored {score} points")
Output:
Maria scored 90 points
city = input("Enter your city: ")
year = int(input("Enter the year you were born: "))
age = 2026 - year
print(f"You live in {city} and you are {age} years old.")
int or floatprint or input