Python Input and Output Tutorial for Beginners | User Input & print() Function
Every useful software application interacts with users by accepting input and displaying output. Whether it’s a login page, calculator, banking application, or AI chatbot, the ability to receive information from users and present meaningful results is a fundamental programming skill.
In this lesson, you’ll learn how to use Python’s input() function to accept user input and the print() function to display information. You’ll also explore formatted output, string formatting, type conversion, escape characters, and practical examples that demonstrate how interactive programs work.
By the end of this lesson, you’ll be able to create programs that communicate with users, process their input, and display clear and professional output.
Learning Objectives
After completing this lesson, you will be able to:
- Understand the concept of input and output.
- Use the
print()function effectively. - Accept user input using the
input()function. - Convert input into appropriate data types.
- Display formatted output.
- Use escape characters in strings.
- Build interactive Python applications.
- Avoid common mistakes when working with user input.
Topics Covered
- Introduction to Input and Output
- The print() Function
- The input() Function
- Type Conversion
- Formatted Strings (f-Strings)
- Escape Characters
- Multiple Inputs
- User Interaction
- Best Practices
Detailed Lesson Content
Introduction to Input and Output
Imagine you’re using an ATM. You enter your PIN, choose a transaction, and receive your account balance. Similarly, when you shop online, you enter your shipping address, payment details, and receive an order confirmation.
These interactions involve two basic operations:
- Input: Information entered by the user.
- Output: Information displayed by the program.
Without input and output, programs would not be interactive. They would simply execute predefined instructions without responding to user actions.
Python provides two built-in functions for this purpose:
input()– Receives data from the user.print()– Displays data on the screen.
These functions form the foundation of almost every Python application.
The print() Function
The print() function is used to display information on the screen.
Syntax
print("Hello, World!")
Output
Hello, World!
You can print different types of data.
print("Welcome to Mango Engineers")
print(2026)
print(95.5)
print(True)
Output
Welcome to Mango Engineers
2026
95.5
True
Printing Variables
Variables can also be displayed using print().
name = "Rahul"
age = 22
print(name)
print(age)
Output
Rahul
22
Printing Multiple Values
Python allows multiple values to be printed in a single statement.
name = "Rahul"
course = "Python"
print(name, course)
Output
Rahul Python
Custom Separator
Use the sep parameter to separate values with a custom character.
print("Python", "Java", "React", sep=" | ")
Output
Python | Java | React
Custom End Character
The end parameter changes the default line break.
print("Welcome", end=" ")
print("Students")
Output
Welcome Students
The input() Function
The input() function accepts data entered by the user.
Syntax
input("Message")
Example:
name = input("Enter your name: ")
print("Welcome", name)
Sample Output
Enter your name: Rahul
Welcome Rahul
Understanding User Input
The value returned by input() is always a string, even if the user enters a number.
Example:
age = input("Enter your age: ")
print(type(age))
Output
<class 'str'>
This is an important concept because mathematical operations require numeric data types.
Type Conversion
Suppose you want to add two numbers entered by the user.
Incorrect approach:
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
print(num1 + num2)
Input
10
20
Output
1020
The values are treated as strings and concatenated.
Correct approach:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print(num1 + num2)
Output
30
Float Input
To accept decimal numbers:
salary = float(input("Enter Salary: "))
Example:
45000.75
Boolean Values
Python doesn’t directly convert user input into Boolean values.
Instead:
choice = input("Continue? (yes/no): ")
print(choice.lower() == "yes")
Formatted Output Using f-Strings
Python provides f-Strings for clean and readable output.
Example:
name = "Rahul"
course = "Python"
print(f"Hello {name}, welcome to the {course} course.")
Output
Hello Rahul, welcome to the Python course.
This is the recommended way to display variables in modern Python.
Escape Characters
Escape characters help format text.
| Escape Character | Description |
|---|---|
\n |
New Line |
\t |
Tab Space |
\" |
Double Quote |
\\ |
Backslash |
Example:
print("Python\nProgramming")
Output
Python
Programming
Multiple Inputs
You can accept multiple inputs separately.
first_name = input("First Name: ")
last_name = input("Last Name: ")
print(first_name, last_name)
Or in one line:
first, last = input("Enter First and Last Name: ").split()
Real-World Example: Student Registration Form
name = input("Enter Student Name: ")
age = int(input("Enter Age: "))
course = input("Enter Course: ")
city = input("Enter City: ")
print("\nStudent Details")
print("----------------")
print(f"Name : {name}")
print(f"Age : {age}")
print(f"Course : {course}")
print(f"City : {city}")
Sample Output
Student Details
----------------
Name : Rahul
Age : 21
Course : AI Python Full Stack
City : Jaipur
Real-World Example: Simple Calculator
num1 = float(input("Enter First Number: "))
num2 = float(input("Enter Second Number: "))
sum = num1 + num2
print(f"The Sum is {sum}")
Output
Enter First Number: 25
Enter Second Number: 15
The Sum is 40
Common Mistakes Beginners Make
❌ Forgetting to convert input to numbers.
age = input("Age: ")
age + 5
This produces an error.
✔ Correct:
age = int(input("Age: "))
print(age + 5)
Best Practices
- Always provide meaningful prompts.
- Use type conversion when accepting numbers.
- Prefer f-Strings for formatted output.
- Validate user input whenever possible.
- Keep prompts simple and user-friendly.
- Use descriptive variable names.
Key Takeaways
print()displays information.input()accepts user input.input()always returns a string.- Use
int(),float(), orstr()for type conversion. - f-Strings provide clean and readable output.
- Escape characters improve formatting.
- Interactive applications rely heavily on input and output operations.
Assignment
Create a Student Registration Program that:
- Accepts the student’s name.
- Accepts age.
- Accepts city.
- Accepts course name.
- Accepts percentage.
- Displays all details using formatted output (f-Strings).
Bonus Challenge: Calculate whether the student is eligible for placement if the percentage is 75% or above.



