Input in Python by R4R Team

Python3

provide build-in function input() to take input or data from the user at the runtime of the program. python have print() function for display the data and input() for get the data, but here input() function have a capability of display and get the data from user side simultaneously.

Syntax : var=input([argument])
here argument is optional and var is a variable name.


program to take input -

print("Enter something")
#without argument
a=input()
print(a)
#with argument
a=input("Enter something")
print(a)
#take number input
a=input("Enter number")
print(type(a))
a=int(input("Enter number"))
print(type(a))
print("Number is : "+str(a))


output-

Enter something
programming is cool
programming is cool
Enter something
so what ?
so what ?
Enter number
12
'str'
Enter number
12
'int'
Number is : 12


- 'a' is a variable and data type depends on input function. In python language we do not require to initilize the data type of the variable in our programming.
-term 'type' is use to identify the type of varible that in which class it belongs and in case of input() in python its type is 'str'. so for converting the string type to numeric type we do type casting here.
-In this program first it display the output to the user screen that 'enter something' when user insert data then input() function store the data and refered to variable 'a' then it display the value of a by print() function and in case of last input it get number but it actually behave as a string so we use int for type casting.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!