Reading User Input in Python With Code Sample
In this article, I will explain how to read user input in Python. Python 2 and Python 3 differ slightly in the ways that they support reading user input. Though the main focus of this article would be to demonstrate how to read user input in Python 3, I will quickly touch upon the Python 2 approach as well and explain how it differs from Python 3 Reading User Input in Python 3 Python 3 provides a method input() . You can use this to read input that a user enters. This method treats the value entered by a used as a String. The following code demonstrates this: name = input("Enter your name:")print("Hello ",name) The input() method accepts as parameter a String that it displays to the user It then assigns the value that the user enters to the name variable The input() method converts the value entered by a user to String . So, if you want to read an integer type, you need to use typecasting. Python provides an in-built method int() that converts a value to an Intege