Important Notice:

Accepting Input (input())

Accepting Input (input())

8 views 1 min read

Accepting Input (input()) :-

input() Python का एक Built-in Function है, जिसका उपयोग User से Keyboard के माध्यम से Input (डेटा) प्राप्त करने के लिए किया जाता है।

input() Function हमेशा String (str) प्रकार का Data Return करता है, चाहे User Number, Decimal Number या कोई अन्य Value ही क्यों न दर्ज करे।

variable_name = input("Message")

यदि input() के साथ int(), float() या किसी अन्य Type Conversion Function का उपयोग किया जाता है, तो पहले input() String (str) Return करता है, उसके बाद Type Conversion Function उस String को आवश्यक Data Type में Convert (परिवर्तित) कर देता है।

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

English:
input() is a built-in Python function used to accept input (data) from the user through the keyboard.

Syntax -

variable_name = input("Message")

Example 1: Accepting Name -

name = input("Enter your name: ")

print("Name:", name)

Input

Rahul

Output

Name: Rahul

Example 2: Accepting Age -

age = input("Enter your age: ")

print(age)
print(type(age))

Input

18

Output-

18
<class 'str'>
 
note- 

Example 3: Integer Input -

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

print(age)
print(type(age))

Input

18

Output

18
<class 'int'>

Example 4: Float Input -

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

Input

99.5

Output-

99.5
<class 'float'>

Related Notes