Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 24355

Python Morsels: Prompting a user for input

$
0
0

We can prompt our users for input with Python's built-in input function.

Prompting for user input

Python has a built-in input function that we can use to prompt a user of our program to enter some text:

>>> color=input("Favorite color:")Favorite color:▯

Our Python REPL is now hanging and waiting for us (the user) to input text. Let's type purple:

>>> color=input("Favorite color:")Favorite color:purple▯

After the user has typed the text they'd like to enter, they can hit the Enter key to lock-in the value.

>>> color=input("Favorite color:")Favorite color:purple>>>

Now the color variable contains the string purple:

>>> color'purple'

Customizing the prompt text

Note that the input function …

Read the full article: https://www.pythonmorsels.com/prompting-for-input/


Viewing all articles
Browse latest Browse all 24355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>