MyInternships.in

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.

Basic input example
Python
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.

Converting numeric input
Python
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.

Python
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.

Custom separator and ending
Python
print("apple", "mango", "banana", sep=", ")
print("Loading", end="...")
print("Done")
Output
Output
apple, mango, banana
Loading...Done

Formatting Output

For clean, readable output, combine variables inside an f-string rather than joining many pieces with +.

Python
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.

Related Python Topics

Keep learning with these closely related lessons.

Ready to use your Python skills?

Find Python, data science and software internships and fresher jobs across India.

Browse Python Internships