Python Input & Output
Python में User से Input लेना और Output को Screen पर दिखाना सीखें।
इस lesson में हम सीखेंगे कि Python में print() और input() functions का उपयोग कैसे किया जाता है।
हम एक ऐसा program भी बनाएंगे जिसमें User से उसका नाम और उम्र पूछकर उसे Screen पर दिखाया जाएगा।
🐍 Input और Output क्या होता है?
किसी भी program में Computer से information लेना और उसका result दिखाना बहुत महत्वपूर्ण होता है।
User से information लेने को Input कहा जाता है, जबकि Computer द्वारा result दिखाने को Output कहा जाता है।
Input → User से जानकारी लेना
Output → Result को Screen पर दिखाना
🖥️ Python में Output — print()
Python में किसी Text या Value को Screen पर दिखाने के लिए print() function का उपयोग किया जाता है।
Example:
print("Hello World")
Output:
Hello World
📢 एक से अधिक चीजें Print करना
print("My name is Rahul")
print("I am learning Python")
print("Python is easy")
Output:
My name is Rahul
I am learning Python
Python is easy
📦 Variable को Print करना
हम Variable के अंदर stored value को भी print() की सहायता से Screen पर दिखा सकते हैं।
name = "Rahul"
age = 20
print(name)
print(age)
Output:
Rahul
20
⌨️ Python में Input — input()
Python में User से information लेने के लिए input() function का उपयोग किया जाता है।
Example:
name = input("Enter your name: ")
print(name)
Program चलाने पर Computer User से उसका नाम पूछेगा।
Example Output:
Enter your name: Rahul
Rahul
🎯 Input और Output को साथ में इस्तेमाल करना
अब हम User से उसका नाम पूछेंगे और फिर उसे एक Message दिखाएँगे।
name = input("Enter your name: ")
print("Hello", name)
Output:
Enter your name: Rahul
Hello Rahul
🎂 User की Age लेना
अब User से उसकी Age लेते हैं।
age = input("Enter your age: ")
print("Your age is", age)
Example:
Enter your age: 20
Your age is 20
Python में
input() से प्राप्त value
सामान्यतः String होती है।
🔢 Number के रूप में Input लेना
अगर हमें User से कोई संख्या लेकर उस पर Mathematical calculation करनी है, तो हम int() का उपयोग कर सकते हैं।
age = int(input("Enter your age: "))
print("Your age is", age)
➕ दो Numbers को जोड़ना
अब हम User से दो Numbers लेंगे और उनका Sum निकालेंगे।
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum = num1 + num2
print("Sum =", sum)
Example Output:
Enter first number: 10
Enter second number: 20
Sum = 30
🚀 Complete Python Program
अब एक छोटा सा program बनाते हैं जिसमें User से उसका नाम, उम्र और शहर पूछा जाएगा।
name = input("Enter your name: ")
age = int(input("Enter your age: "))
city = input("Enter your city: ")
print("Name:", name)
print("Age:", age)
print("City:", city)
Example Output:
Enter your name: Rahul
Enter your age: 20
Enter your city: Jaipur
Name: Rahul
Age: 20
City: Jaipur
🧠 Practice Question
ऐसा Python program बनाइए जिसमें User से:
- उसका नाम पूछा जाए।
- उसकी उम्र पूछी जाए।
- उसका favourite subject पूछा जाए।
फिर इन सभी information को Screen पर Print करें।
Solution:
name = input("Enter your name: ")
age = int(input("Enter your age: "))
subject = input("Enter your favourite subject: ")
print("Name:", name)
print("Age:", age)
print("Favourite Subject:", subject)
❓ Frequently Asked Questions
Python में Output दिखाने के लिए किस function का उपयोग होता है?
Python में Output दिखाने के लिए print() function का उपयोग किया जाता है।
Python में User से Input कैसे लेते हैं?
User से Input लेने के लिए Python में input() function का उपयोग किया जाता है।
input() से मिलने वाली value किस Data Type की होती है?
input() से प्राप्त value सामान्यतः String यानी str Data Type की होती है।
Number Input लेने के लिए क्या करें?
Number Input लेने के लिए input() के साथ int() या float() का उपयोग किया जा सकता है।
📖 आज हमने क्या सीखा?
- Input और Output क्या होते हैं?
- print() function का उपयोग।
- input() function का उपयोग।
- User से Name और Age लेना।
- int() का उपयोग करके Number Input लेना।
- दो Numbers का Sum निकालना।
🐍 RBSE Python — Python Programming सीखें Step by Step