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


#1

The code is:

hobbies = []

for i in range(3):
  hobby = raw_input("Hey! What is your hobby? ")
  hobbies.append(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?


#2

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?


#3

what exactly do you mean?


#4
for x in hobbies:
    print x

What displays?


#5

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


#6

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.


#7

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