python logic
Steve D'Aprano
steve+python at pearwood.info
Fri Sep 1 10:54:03 EDT 2017
On Fri, 1 Sep 2017 11:30 pm, SS wrote:
> Check out the following simple code:
[...]
Did you read the documentation for the `input` function?
In Python 2, `input` should be avoided, because it evaluates whatever the user
types. Watch this:
py> answer = input('type a number ')
type a number 'abcdefg'.find('e')
py> print answer
4
What you should use is `raw_input`, but remember that it returns a string, not a
number, so if you want a number you have to call int() on the results.
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list