Input and Output in Python in Hindi - Python में Input और Output क्या होता है?
- Python, में input का मतलब यूजर से प्रोग्राम एग्जीक्यूशन के दौरान डेटा प्राप्त करना है जबकि output का मतलब यूजर को सूचना दिखाना या परिणाम को वापस दे ना है।
- Input को आमतौर पर कीबोर्ड के माध्यम से enter किया जाता है और प्रोग्राम उस डेटा को प्रोसेस करता है।
- प्रोसेस करने के बाद आउटपुट को स्क्रीन पर दिखाया जाता है।आए
- Input, प्रोग्राम को इंटरएक्टिव बनाने के लिए और आउटपुट रिजल्ट को समझने के लिए मदद करता है।
- Input, हमेशा टेक्स्ट के रूप में आता है जिसे जरूरत के आधार पर अन्य डेटा टाइप में बदला जाता है।
- Output का उपयोग मुख्यतः messages, results, या errors दिखाने के लिए होता है।
- input और output, एक साथ यूजर और प्रोग्राम के बीच में communication की अनुमति देता है।
Python में Input लेने का तरीका
Python, में `input()` function का उपयोग करके इनपुट लिया जाता है। यह फ़ंक्शन यूज़र से इनपुट लेने के लिए रुकता है और जब यूज़र Enter दबाता है, तब वह इनपुट लेता है।जो भी यूजर टाइप करता है उसे स्ट्रिंग के रूप में प्राप्त किया जाता है। यदि हमें इनपुट को अन्य डेटा टाइप जैसे `int` या `float`में बदलने की जरूरत है तो हम उसे बदलने के लिए type casting functions जैसे int() या float() का उपयोग करते हैं।
Input, को आमतौर पर program execution के दौरान दिया जाता है ताकि उसे dynamic और interactive बनाया जा सके।
Single Input लेना
हम input() function का उपयोग करके यूजर से एक इनपुट लेते हैं।Example1: Single Input (String)
name = input("Enter your name: ")
print("Hello", name)
Output: Enter your name: Dolly Hello Dolly
Example2: Single Input (Integer)
age = int(input("Enter your age: "))
print("You are", age, "years old.")
Output: Enter your age: 30 You are 30 years old.
Example3: Single Input (Float)
marks = float(input("Enter your marks: "))
print("Your marks is:", marks)
Output: Enter your marks: 88.94 Your marks is: 88.94
Multiple Input एक ही Line में लेना(input(), split(), map() function का उपयोग)
हम एक लाइन में कई वैल्यूज को ले सकते हैं। इसके लिए निम्न फंक्शन का उपयोग करते हैंinput()
यह फ़ंक्शन यूज़र से input लेता है string के रूप में, जैसे — `"10 20 30" । यह पूरा input एक लाइन में आता है और text की तरह होता है, न कि नंबर की तरह।.split()
यह फ़ंक्शन इस string को space के आधार पर अलग-अलग हिस्सों में बाँट देता है।
जैसे ['10', '20', '30']
जैसे ['10', '20', '30']
map(int, ...)
जब हम split() से values लेते हैं, तो ये string होती हैं ।जैसे: ['10', '20', '30']
लेकिन हम इनका इस्तेमाल number की तरह करना चाहते हैं। तो यहाँ पर map() काम आता है।
जैसे [10, 20, 30]
Example 1: Two Numbers (Strings)
a, b = input("Enter your hobbies: ").split()
print("Hobby 1:", a)
print("Hobby 2:", b)
Output: Enter your hobbies: Music Singing Hobby 1: Music Hobby 2: Singing
Explanation:
ऊपर का code, एक ही line में दो शब्दो को लेता है और उसे space का उपयोग कर splits कर देता है।
ऊपर का code, एक ही line में दो शब्दो को लेता है और उसे space का उपयोग कर splits कर देता है।
Example 2: Two Numbers (Integers)
x, y = map(int, input("Enter two numbers: ").split()) print("Sum:", x + y)
Output: Enter two numbers: 10 15 Sum: 25
Explanation:
map(int, ...) function दोनों inputs को integer में बदल देता है।
map(int, ...) function दोनों inputs को integer में बदल देता है।
Example 3: Three Float Numbers
p, q, r = map(float, input("Enter three decimal numbers: ").split())
print("Average:", (p + q + r) / 3)
Output: Enter three decimal numbers: 56.70 96.44 88.34 Average: 80.49333333333333
Explanation:
map(float, ...) function तीनो inputs को integer में बदल देता है। उसके बाद उसके average की गणना की जाती है।
map(float, ...) function तीनो inputs को integer में बदल देता है। उसके बाद उसके average की गणना की जाती है।
Example 4: List of Words
fruits = input("Enter some fruits name: ").split()
print("Fruits list:", fruits)
Output: Enter some fruits name: Apple Orange Pear Fruits list: ['Apple', 'Orange', 'Pear']
Python में Output दिखाने का तरीका
Python, में output दिखाने के लिए built-in functions का उपयोग किया जाता है जो डेटा को स्टैंडर्ड आउटपुट डिवाइस आमतौर पर स्क्रीन पर भेजता है।Python में Output दिखाने के लिए सबसे आम तरीका print() function है। यह function values या expressions को input की तरह लेता है और रिजल्ट को text रूप में प्रदर्शित करता है।
Python, डेटा को दिखाने से पहले उसे अपने आप पढ़ने लायक टेक्स्ट में बदल देता है। आउटपुट आमतौर पर लाइन दर लाइन दिखाया जाता है।
Multiline Printing
आप print() function का उपयोग करके निम्न प्रकार से एक एक line को print कर सकते हैं।
इसे निम्न प्रकार से उदाहरणों से समझते हैं।
Example1: Basic Text Output
print("Hello, Students!")
print("Welcome to our site computer ehub.")
print("Let's learn something new.")
print("This is fun!")
print("Keep practicing.")
Output: Hello, Students! Welcome to our site computer ehub. Let's learn something new. This is fun! Keep practicing.
Example2: Printing Variables
name = "Surya" age = 25 print("Name:", name) print("Age:", age) print("Present:", True) print("Completed:", 90, "%"
Output: Name: Surya Age: 25 Present: True Completed: 90 %
Example3: Print with Separator (sep का उपयोग करना)
# Using sep in print
day = "08"
month = "07"
year = "2025"
print("Date is:", day, month, year)
print(day, month, year, sep="-")
print("Done printing date.")
Output: Date is: 08 07 2025 08-07-2025 Done printing date.
Example4: Print without New Line (end का उपयोग करना)
# Using end in print
print("Hello", end=" ")
print("Students!")
print("computerehub", end=" - ")
print("is", end=" - ")
print("great")
print("Place")
print("to learn")
Output: Hello Students! computerehub - is - great Place to learn
Example5: Print Expressions / Calculations
# Printing results of expressions a = 10 b = 5 print("Addition:", a + b) print("Subtraction:", a - b) print("Multiplication:", a * b) print("Division:", a / b)
Output: Addition: 15 Subtraction: 5 Multiplication: 50 Division: 2.0
Single line Printing
Python में single line printing का मतलब print() function का उपयोग करके text या result को एक लाइन में दिखाना है। इसे निम्न प्रकार से उदाहरणों से समझते हैं।
Example 1: Print Multiple Strings
print("Python", "is", "easy", "to", "learn.")
Output:
Python is easy to learn.
Example 2: तीन अलग-अलग Values
a = 10
b = 20
c = 30
print("Values are:", a, b, c)
Output: Values are: 10 20 30
Example 3: Math Result in One Line
a = 5
b = 7
print("Sum:", a + b, "| Product:", a * b, "| Difference:", a - b
Output:
Sum: 12 | Product: 35 | Difference: -2
Output Formatting in Python in Hindi
Output formatting का मतलब यह नियंत्रित करना कि आउटपुट कैसे दिखाई देता है। हम उसे `print()` function का उपयोग करके प्रदर्शित करते हैं।यह आउटपुट को साफ करने योग्य और प्रोफेशनल बनाने में मदद करता है।
Output Formatting के कुछ सामान्य methods
1.print() मे Commas का उपयोग करना:
spaces के साथ स्वचालित रूप से वैल्यू को प्रिंट करता है।
spaces के साथ स्वचालित रूप से वैल्यू को प्रिंट करता है।
name = "Sumit"
age = 25
print("Name:", name, "Age:", age)
Output: Name: Sumit Age: 25
2.String Concatenation (+) का उपयोग करना:
name = "Amita"
print("Good morning, " + name + "!"
Output: Good morning, Amita!
3.`format()` Method का उपयोग करना:
format()` function का उपयोग `{}` का उपयोग करके variables या values को एक string के अंदर insert करने के लिए किया जाता है।
format()` function का उपयोग `{}` का उपयोग करके variables या values को एक string के अंदर insert करने के लिए किया जाता है।
name = "John" marks = 90 print("Student Name: {} | Marks: {}".format(name, marks)
Output: Student Name: Anil | Marks: 90
4. Decimal Points को नियंत्रित करना:
price = 49.9876 print(f"Price: {price:.2f}")
Output: Price: 49.99
6. f-string का उपयोग करना:
इसका उपयोग variables या expressions को आसानी से strings, के अंदर insert करने के लिए किया जाता है।
इसका उपयोग variables या expressions को आसानी से strings, के अंदर insert करने के लिए किया जाता है।
a = 10
b = 5
print(f"Sum is {a + b}")
Output: Sum is 15
7.Text Output को Align करना:
print("{:<10>5}".format("Item", "Qty")) print("{:<10>5}".format("Pen", 3)) print("{:<10>5}".format("Notebook", 10))
Output: Item Qty Pen 3 Notebook 10
0 टिप्पणियाँ