Getting input from the user

You can also use the input() function to get input from the user. Use the prompt string you want displayed to the user as input's parameter:

>>> name = input("Name? ") Name? Vern >>> print(name) Vern

>>> age = int(input("Age? ")) Age? 28 >>> print(age)

This is a fairly simple way to get user input. The one catch is that the input comes in as a string, so if you want to use it as a number, you have to use the int() or float() function to convert it.

Was this article helpful?

0 0

Post a comment