Python Basics
Python User Input and Output
Programs become interactive when they can take input from a user and display meaningful output back — Python makes both very simple.
Taking Input with input()
The input() function pauses your program, waits for the user to type something and hit Enter, then returns whatever they typed — always as a string.
name = input("What is your name? ")
print("Hello, " + name + "!")input() always returns a string, even if the user types a number. Use int() or float() to convert it before doing math.
age = int(input("Enter your age: "))
print(f"Next year you will be {age + 1}")Displaying Output with print()
The print() function sends output to the screen, and it accepts multiple values separated by commas.
print("Name:", "Rahul", "Age:", 24)Controlling Output with sep and end
By default, print() separates values with a space and ends with a new line. You can change both using the sep and end parameters.
print("apple", "mango", "banana", sep=", ")
print("Loading", end="...")
print("Done")apple, mango, banana
Loading...DoneFormatting Output
For clean, readable output, combine variables inside an f-string rather than joining many pieces with +.
name = "Divya"
marks = 88.5
print(f"{name} scored {marks} marks")Always label your output clearly, like "Total: 500" instead of just "500" — it makes programs much easier to read and debug.
