Python provides developers with built-in functions that can be used to get input directly from users and interact with them using the command line (or shell as it is often called). Python 2 programmers use the function raw_input() to accomplish this task. Python 3 introduced the new input() function. The two functions have the same semantics.
Consider the following Python 3 code:
name = input('Enter your name: ')
This will display the sentence ‘Enter your name:’ as a prompt in the shell. Python will then wait until the user types something on the command line, followed by hitting the enter key. Whatever the user types will be the return value of the input() function. It is important to note that this value will always be treated as a string by Python. In our current example, the string will be assigned to the variable ‘name’. To produce the same result in
from Planet SciPy
read more
No comments:
Post a Comment