Python Input and Output


Python provides simple functions to take input from the user and output data to the screen.

  • 📥 Input → Collect data from the user using the input() function

  • 📤 Output → Display data using the print() function


🖨️ Output in Python – print()

The print() function is used to show messages or variable values on the screen.

Syntax:

print(value1, value2, ..., sep=' ', end='\n')
✅ Examples:
print("Hello, World!")  
print("Name:", "John")  
print("Hello", end=" ")  
print("World!")
  • sep: Separator between values (default is space)

  • end: What to print at the end (default is newline \n)


🎤 Input in Python – input()

The input() function reads a line of text entered by the user.

Syntax:

variable = input("Enter something: ")
  • The input is always received as a string, even if the user types a number.

  • You can convert it to int/float using int() or float().

✅ Examples:
name = input("Enter your name: ")
age = int(input("Enter your age: "))

🔄 Type Casting with Input

Since input() returns a string, you can cast it like this:

num1 = int(input("Enter number 1: "))
num2 = float(input("Enter number 2: "))

🧠 Summary Table

Operation Function Returns
Display output print() None
Get input input() str

Practice Questions

Q1. Write a Python program to display your name using the print() function.

Q2. Write a Python program to take the user's name as input and greet them with a message.

Q3. Write a Python program to accept two numbers from the user and display their sum.

Q4. Write a Python program to ask the user to enter their age and display it with a message like “You are 25 years old”.

Q5. Write a Python program to use end=' ' and print two words on the same line.

Q6. Write a Python program to accept a float number from the user and print its type.

Q7. Write a Python program to take input for a subject name and print a sentence using it, like “I love Math”.

Q8. Write a Python program to ask the user to enter 3 words and print them separated by commas using sep=','.

Q9. Write a Python program to take a string input and convert it to uppercase before printing.

Q10. Write a Python program to get two numbers from the user and display their product.


Go Back Top