For your hobbies

for hobby in range(3):
    hobby = raw_input("What is your hobby?") 
    print hobbies

When I put this code in, I get a weird output.

What is your hobby? roller derby
[u'roller derby']
What is your hobby? cooking
[u'roller derby', u'cooking']
What is your hobby? eating
[u'roller derby', u'cooking', u'eating']

How can I get rid of the 'u' before every hobby listed?


Mmm, try something like this, maybe?

print ", ".join(hobbies)

Instead of

print hobbies

The u there is not an error, by the way (in case you were thinking that).


I just used "print hobby" instead of "print Hobbies" and that worked fine! :slightly_smiling:


That u just means that it is a Unicode string. Here's how to remove them:


Call str() on a unicode string to create a regular string. String literals with a u prepended e.g. u'string' are unicode strings.


a = u'hello'
=> a
=> str(a)

Credits to Rafe Kettler


I wrapped my definition of hobby variable in str() in order to get rid of the unicode prefix.

for i in range(3):
hobby = str(raw_input("Name one of your hobbies: "))

print (hobbies)

Result after running

Name one of your hobbies: guitar
Name one of your hobbies: sports
Name one of your hobbies: gym
['guitar', 'sports', 'gym']


From what I've seen it seems there is a bug in this module.

My very first attempt at this I typed it out exactly how I thought it should be, running into troubles I went to the forum to find what I was missing, NOTHING is the answer yet I still got syntax errors. after resetting the code and entering the EXACT same code, it worked.

Try resetting the code and writing it all over, it seems to work, not sure why it ran into errors the first time.


I see nothing wrong with it.