In Python, you can interact with users using the input() function for input and the print() function for output.
The input() function reads a line from user input as a string:
name = input("Enter your name: ")
print("Hello, " + name + "!")
Use int(), float(), or bool() to convert string input:
age = int(input("Enter your age: "))
print("You will be", age + 1, "next year.")
The print() function displays data on the screen:
print("Welcome to Technorank!")
print("Python", "is", "fun", sep=" - ")
print("Loading...", end=" Done!\n")
You can use f-strings for clean output:
name = "Amit"
score = 95
print(f"{name} scored {score} marks.")
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!