Input and Output in Python

📘 Python 👁 62 views 📅 Nov 05, 2025
⏱ Estimated reading time: 2 min

Input and Output in Python

Python provides simple ways to take input from users and display output.


1. Output Using print()

  • The print() function displays text, variables, or expressions.

# Simple output print("Hello, Python!") # Printing multiple values name = "Alice" age = 25 print("Name:", name, "Age:", age) # Using formatted strings (f-strings) print(f"My name is {name} and I am {age} years old.") # Using separator and end print("Python", "is", "fun", sep="-", end="!\n") # Output: Python-is-fun!

2. Input Using input()

  • The input() function reads user input as a string.

# Take user input name = input("Enter your name: ") age = input("Enter your age: ") print(f"Hello {name}, you are {age} years old.")

3. Type Conversion for Input

  • input() always returns a string, so convert to required data type:

# Convert input to integer num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) sum = num1 + num2 print(f"Sum: {sum}") # Convert to float height = float(input("Enter your height in meters: "))

4. Reading Multiple Inputs

  • Using split() to read multiple values:

# Enter multiple numbers separated by space numbers = input("Enter numbers: ").split() # Convert each to integer numbers = [int(num) for num in numbers] print(numbers)

5. Key Points

  • print() is used for output, supports multiple arguments, formatting, and separators.

  • input() is used for user input, always returns a string.

  • Use type conversion (int(), float()) to handle numeric inputs.

  • split() and list comprehension help read multiple inputs efficiently.


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes