Python Input and Output Explained for Beginners (input(), print())
Python Input and Output Explained for Beginners (input(), print())
Introduction
In the previous post, we learned about Python data types. Now let's see how to interact with the user and display output in Python.
1️⃣ The print() Function
The print() function is used to display output on the screen.
print("Hello, Python!")
name = "Ayush"
print("My name is", name)
print().
2️⃣ The input() Function
The input() function allows you to take input from the user. It always returns a string, so you may need to convert it for numbers.
name = input("Enter your name: ")
print("Hello,", name)
age = int(input("Enter your age: "))
print("You are", age, "years old")
int() or float() to convert user input into numbers.
3️⃣ Combining Input and Output
You can ask multiple questions and print them together.
name = input("Name: ")
age = int(input("Age: "))
print("Name:", name, "| Age:", age)
Summary
- print() → Displays output
- input() → Takes input from user
- Convert inputs to int or float if needed
What You Learned in This Post
- How to print text and variables
- How to take input from the user
- How to convert input into numbers
What’s Next?
Now that you can take input and display output, the next step is learning Python operators to perform calculations.
Next Post: Python Operators Explained for Beginners (+, -, *, /, %)
👋 About the Author
Ayush Gupta
MSc AI/ML Student | Machine Learning & Python Enthusiast
📧 Email:
aygupta9898@gmail.com
Comments
Post a Comment