In this tutorial, we will see how to take input from user in Python programming language. We use input() function in Python to get user input.
Get String input from user
In this program we will see how to receive string input from user in Python.
# Python Program - Get String Input from User str = input("Enter any string: ") print(str)
Get Integer Input from user
As we have seen in the above example that when we receive the input using input() function it is considered as String. To convert the string input to integer we use the int() function over the received input.
# Python Program - Get Integer Input from User num = int(input("Enter an Integer: ")) print(num)
Get Float Input from user
This is similar to what we have seen above, except that we use float() function to convert the received input into a float value.
# Python Program - Get Float Input from User num = float(input("Enter a float value: ")) print(num)