This article will demonstrate how to utilize the Python programming language to receive user input. In Python, the input() method is used to collect user input.
Get String input from user
This application demonstrates how to accept user-provided string input in Python.
# Python Program - Get String Input from User str = input("Enter any string: ") print(str)
Get Integer Input from user
As seen in the example above, the input is treated as a String when it is received using the input() method. We utilize the int() method on the received input to convert the string input to an integer.
# 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 saw earlier, with the exception that the incoming input is converted into a float value using the float() method.
# Python Program - Get Float Input from User num = float(input("Enter a float value: ")) print(num)