10/14 Weird output


#1

Hi,

my code is:

hobbies = []

# Add your code below!
for i in range(3):
    hobby = raw_input("What is your hobby?")
    hobbies.append(hobby)
print hobbies

But it prints (with answers: "d", "s", "z")

What is your hobby? d
What is your hobby? s
What is your hobby? z
[u'd', u's', u'z']
None

Why output in brackets is so weird? Where comes this 'u' from?

EDIT: When I changed my code to this

hobbies = []

# Add your code below!
for i in range(3):
    hobby = raw_input("What is your hobby?")
    hobbies.append(hobby)

print " ".join(hobbies)
print hobbies

the output switched to this:

What is your hobby? d
What is your hobby? s
What is your hobby? z
d s z
[u's', u'v', u'h']
None

So what's wrong with print hobbies?


#2

Reference: Python string prints as [u'String']

The u stands for unicode. We can get around this by converting to UTF-8.

hobbies.append(hobby.encode("utf-8"))
`


#3

Hmm, but why it comes in this exercise, I didn't meet this earlier?

But thanks for explanation.


#4

Can't say why, only that it does not affect the lesson checker. It will come up at some point along the way. Consider this a lesson in quick research.


#5

Ok, thank you, mate.