Lesson 10 Weird Output



What is one of your hobbies? kiting
What is one of your hobbies? flying
[u'kiting', u'flying']
What is one of your hobbies? gliding
[u'kiting', u'flying', u'gliding']

What is with the weird output when I .append() to the list? Where does the u' party come from? I get the same thing if I define a new variable, hobby, inside the for loop instead of using 'i'.

hobbies = []

# Add your code below!
for i in range(0,3):
    i = raw_input("What is one of your hobbies?")
    print hobbies


The u is because those are unicode strings, there's nothing wrong with them, python just adds the u so you know it's a unicode string and not a byte string. If you want to remove them you convert i to a string before appending like so:


Not entirely sure the difference between unicode strings and byte strings, but the terms sound vaguely familiar. Anyway, thanks! I guess that makes sense since i is referring to index values, which are not strings?


I'm not exactly sure on this, but I believe that it comes from raw_input() and that's is the format it stores its strings as.


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