In this tutorials, I am going to show you how to read input from the keyboard in python.
Python raw_input :
Python raw_input is a python function used to read the input from keyboard in the form of String.
raw_input() Example :
Sample.py
x=raw_input("Enter any value : ")
print x
print type(x)
If we use raw_input() function, whatever the type of data we given as an input, it will internally convert as string type. We can check the type of data using type(x) function.
Note : The raw_input() function has been deprecated in python 3.x instead we can use python input() function.
Lets run the above sample code :
$ python sample.py
Enter any value : chandra
chandra
<type 'str'>
$ python sample.py
Enter any value : 1234
1234
<type 'str'>
$ python sample.py
Enter any value : 1.235
1.235
<type 'str'>
Happy Learning 🙂