Python Input and Output क्या है? input() और print() Function | RBSE Class 12

इस लेख में: Python में User से Input लेना और Output दिखाना, input(), print(), type conversion, int(), float(), str(), multiple inputs और practical Python programs आसान हिंदी में सीखेंगे।

Python Input और Output क्या है?

किसी program में user से information प्राप्त करना Input कहलाता है और program द्वारा result या information को screen पर दिखाना Output कहलाता है।

Python में user से input लेने के लिए मुख्य रूप से input() function और output display करने के लिए print() function का उपयोग किया जाता है।

याद रखें:
Input → User से data लेना
Output → User को result दिखाना

Python में Output कैसे दिखाएँ?

Python में output display करने के लिए print() function का उपयोग किया जाता है।

Example 1: Simple Output

print("Hello Python")

Output:

Hello Python

Example 2: Number का Output

print(100)

Output:

100

Example 3: Calculation का Output

print(10 + 20)

Output:

30

print() Function क्या है?

print() Python का built-in function है जिसका उपयोग information, text, variables और expressions को output के रूप में display करने के लिए किया जाता है।

name = "Rahul"

print(name)

Output:

Rahul

एक से अधिक Values कैसे Print करें?

print() function में एक से अधिक values को comma से अलग करके display किया जा सकता है।

name = "Rahul"
age = 18

print(name, age)

Output:

Rahul 18

Text और Variable को साथ में Print करना

name = "Rahul"
age = 18

print("Name:", name)
print("Age:", age)

Output:

Name: Rahul
Age: 18

Python में User से Input कैसे लें?

Python में user से data प्राप्त करने के लिए input() function का उपयोग किया जाता है।

Simple Input Example

name = input("Enter your name: ")

print(name)

Program चलाने पर user अपना नाम enter कर सकता है।

input() Function क्या है?

input() Python का built-in function है जो user से keyboard के माध्यम से input प्राप्त करता है।

उदाहरण:

name = input("Enter your name: ")

print("Hello", name)

यदि user Rahul enter करता है तो output होगा:

Hello Rahul

Important: input() से प्राप्त Data का Type

बहुत महत्वपूर्ण:

Python में input() function से प्राप्त input सामान्यतः string के रूप में मिलता है।

उदाहरण:

age = input("Enter your age: ")

print(type(age))

यदि user 18 enter करता है, तब भी input को text/string के रूप में प्राप्त किया जाता है।

Input को Integer में कैसे Convert करें?

यदि user से integer number लेना है तो int() function का उपयोग किया जा सकता है।

age = int(input("Enter your age: "))

print(age)

अब entered value को integer में convert किया जा सकता है।

Input को Float में कैसे Convert करें?

Decimal number प्राप्त करने के लिए float() function का उपयोग किया जा सकता है।

price = float(input("Enter price: "))

print(price)

String में Convert करना

किसी value को string में convert करने के लिए str() function का उपयोग किया जा सकता है।

age = 18

text = str(age)

print(text)

Type Conversion क्या है?

एक data type की value को दूसरे compatible data type में बदलना Type Conversion कहलाता है।

Python में commonly इस्तेमाल होने वाले functions:

Function उपयोग
int() Integer में conversion
float() Float में conversion
str() String में conversion
bool() Boolean में conversion

दो Numbers का Addition Program

यह RBSE Class 12 के practical और basic programming के लिए एक महत्वपूर्ण example है।

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

तीन Numbers का Average निकालना

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

average = (a + b + c) / 3

print("Average =", average)

Student Marks Program

name = input("Enter student name: ")

marks = float(input("Enter marks: "))

print("Student:", name)
print("Marks:", marks)

print() में sep Parameter

sep parameter का उपयोग print() में multiple values के बीच separator निर्धारित करने के लिए किया जा सकता है।

print("2026", "08", "20", sep="-")

Output:

2026-08-20

print() में end Parameter

end parameter यह निर्धारित कर सकता है कि print() के बाद क्या जोड़ा जाए।

print("Hello", end=" ")
print("Python")

Output:

Hello Python

f-string से Output Formatting

Variables को text के साथ readable तरीके से display करने के लिए f-string का उपयोग किया जा सकता है।

name = "Rahul"
age = 18

print(f"My name is {name} and my age is {age}.")

Output:

My name is Rahul and my age is 18.

एक ही Line में Multiple Input

Python में एक line में multiple values input लेकर उन्हें अलग-अलग variables में assign किया जा सकता है।

a, b = input("Enter two values: ").split()

print(a)
print(b)
Note: split() input को अलग-अलग parts में बाँटता है। यदि numbers पर arithmetic operation करना हो तो उन्हें appropriate numeric type में convert करना आवश्यक हो सकता है।

Multiple Integer Input

a, b = map(int, input("Enter two numbers: ").split())

print("Sum =", a + b)

यदि user input देता है:

10 20

तो output होगा:

Sum = 30

Input और Output का पूरा Practical Program

name = input("Enter your name: ")
age = int(input("Enter your age: "))
marks = float(input("Enter your marks: "))

print("----- Student Details -----")
print("Name:", name)
print("Age:", age)
print("Marks:", marks)

Common Errors in input()

1. Integer Input में गलत Value देना

यदि program में int(input()) का उपयोग किया गया है और user ऐसा text enter करता है जिसे integer में convert नहीं किया जा सकता, तो program error दे सकता है।

2. float() में Invalid Input

इसी प्रकार float() में ऐसी value देने पर conversion error हो सकता है जिसे float में convert नहीं किया जा सकता।

3. Input को Number समझ लेना

यह एक common beginner mistake है।

a = input("Enter number: ")
b = input("Enter number: ")

print(a + b)

यदि input 10 और 20 है तो यह numerical addition के बजाय strings के साथ काम करेगा।

Numbers के लिए:

a = int(input("Enter number: "))
b = int(input("Enter number: "))

print(a + b)

Input और Output में अंतर

Input Output
User से data प्राप्त करना Result या information दिखाना
input() print()
Keyboard से data लिया जा सकता है Screen पर result display किया जा सकता है

RBSE Class 12 Important Questions

  1. Python में input क्या है?
  2. Python में output क्या है?
  3. input() function का उपयोग किसलिए किया जाता है?
  4. print() function का उपयोग किसलिए किया जाता है?
  5. input() से प्राप्त value का सामान्य data type क्या होता है?
  6. int() function का उपयोग क्या है?
  7. float() function का उपयोग क्या है?
  8. Type Conversion क्या है?
  9. sep parameter का क्या उपयोग है?
  10. end parameter का क्या उपयोग है?
  11. दो numbers का sum निकालने का Python program लिखिए।
  12. User से student name और marks लेकर display करने का program लिखिए।

Quick Revision

Concept Important Point
Input User से data लेना
Output Result display करना
input() User से input लेने के लिए
print() Output display करने के लिए
int() Integer conversion
float() Float conversion
str() String conversion
type() Data type check करने के लिए
sep Printed values के बीच separator
end print() के अंत में दिया जाने वाला value

Frequently Asked Questions (FAQs)

Python में Input लेने के लिए कौन सा function है?

Python में user से input लेने के लिए input() function का उपयोग किया जाता है।

Python में Output दिखाने के लिए कौन सा function है?

Python में output display करने के लिए print() function का उपयोग किया जाता है।

input() का return type क्या होता है?

सामान्य रूप से input() user द्वारा enter की गई value को string के रूप में return करता है।

Python में input को integer में कैसे बदलें?

int(input()) का उपयोग करके input को integer में convert किया जा सकता है।

Python में decimal input कैसे लें?

Decimal input के लिए float(input()) का उपयोग किया जा सकता है।

Python में sep क्या है?

sep print() function में multiple values के बीच separator निर्धारित करने के लिए उपयोग किया जाता है।

अब अगला Topic पढ़ें

RBSE Python Study Tip: Input और Output को समझने के बाद खुद से छोटे programs बनाइए—जैसे दो numbers का sum, average, area of circle और student marks program। इससे Python programming की foundation मजबूत होगी।
Official Reference:

Python के input और output तथा built-in functions की विस्तृत जानकारी के लिए Python की official documentation देखें।

Python Built-in Functions Documentation