Lesson 10 Weird Output


#1



https://www.codecademy.com/en/courses/python-beginner-en-cxMGf/1/2?curriculum_id=4f89dab3d788890003000096#


What is one of your hobbies? kiting
[u'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']
None


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?")
    hobbies.append(i)
    print hobbies


#2

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:
hobbies.append(str(i))


#3

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?


#4

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.


#5

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