10\19 - u'run', u'do', u'try'


The code is:

hobbies = []

for i in range(3):
  hobby = raw_input("Hey! What is your hobby? ")
print hobbies

the output is:

Hey! What is your hobby? do
Hey! What is your hobby? try
Hey! What is your hobby? taste
[u’do’, u’try’, u’taste’]

is that supposed to be like this? where do those u’s come from?


raw_input() takes any inputs from the standard input (keyboard, etc.) which does not preclude international characters that do not fall into the ordinal range of ASCII. Python treats all inputs as Unicode to accommodate those characters. That’s what the u means. Notice it is outside of and preceding the string?

Since we won’t normally be dumping our list, but iterating over it to output the contents, this is not a concern. What happens if you print using a loop?


what exactly do you mean?

for x in hobbies:
    print x

What displays?


now it is all right, no u’s. thanks)


I don’t think python2 decodes stdin by default, rather, it reads whatever bytes it gets, because that’s what python2’s string type is. Bytes.
Codecademy has replaced stdin with something that produces unicode strings.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.