Python

Python – Getting Input From User

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)

Output:
Python String Input From User

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)

Output:
Python Int Input User

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)

Output:
Python Float Value Input

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button