Strange append to list?


#1

https://www.codecademy.com/courses/learn-python/lessons/loops/exercises/for-your-hobbies?action=lesson_resume&link_content_target=interstitial_lesson

Lesson is easy enough, and my code should be fine, but the output is what I find weird.

Code:

hobbies = []

# Add your code below!
for each in range(3):
  hobby = raw_input("What's a hobby to add:")
  hobbies.append(hobby)
print hobbies

Output:
What's a hobby to add:not
What's a hobby to add:too
What's a hobby to add:much
[u'not', u'too', u'much']

Why is there a u in front of my list entries?


#2

because raw_input stores the entries as unicode type, you can simple cast it to a string:

str(raw_input("What's a hobby to add:"))

#3

and i guess you can deduce that the u is an abbreviation of unicode


#4

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