input() function in python
Input function is used to take data from the user in a Python program.
syntax: input()
example: a = input()
result: |
NOTE:
आउटपुट में एक ऊर्ध्वाधर लाइन दिखाई देती है जो इनपुट करने को दर्शाता है तथा इनपुट मिलने पर इनपुट() का काम खत्म हो जाता है।
A vertical line appears in the output to indicate that input has been made and input() terminates when input is received.
जब इनपुट फंक्शन किसी वेरिएबल के साथ लिखा होता है तो इनपुट किये गए डाटा को उस वेरिएबल में स्टोर कर दिया जाता है।
When the input function is written with a variable, the inputted data is stored in that variable.
example:
name = input() # "swapnil" is entered
print(name)
result: swapnil
input() with message:
result: enter your name: |
NOTE:
यदि इनपुट फंक्शन से कोई संख्या इनपुट की जाती है तो वह स्ट्रिंग टाइप में बदल जाती है।
If a number is inputted through the input function, it is converted to string type.
example:
a = input() # 3 is entered
print(a +
1) # value of a is in string not int
result: TypeError: can only concatenate str (not "int") to str
NOTE:
स्ट्रिंग को किसी संख्या के साथ जोड़ा नहीं जा सकता इसके लिए पहले आपको स्ट्रिंग में लिखे संख्या को नंबर टाइप में बदलना होगा।
String cannot be joined with a number, for this you must first convert the number written in the string to number type.
example:
a = input() # 3 is entered
a = int(a) # convert '3' to 3
print(a + 1) # prints 3+1
result: 4
ONE LINER:
input() और int() को एक लाइन में भी लिखा जा सकता है।
input() and int() can also be written in one line.
a = int( input() )
OTHER TOPIC:
---END---

Comments
Post a Comment