10/19, why is the console printing out extra stuff?


So I have

hobbies = []

for i in range(3):
  hobby = raw_input("Gimme hobby: ")
print hobbies

And if I put in, say,

Gimme hobby: cooking
Gimme hobby: shopping
Gimme hobby: fishing

It outputs

[u'cooking', u'shopping', u'fishing']

But I didn’t put the u or the quotes there. Is something happening behind the scenes I am not aware of?


yes, the result of raw_input is stored as unicode:


then i don’t have to tell you what the u stands for


There HAS to be something going on behind the scene, because you haven’t specified how that value should be printed. (What output did you expect?)


Thank you–a little confused still but I’ll accept it as is for now.


The output I expected was:

[cooking, shopping, fishing]

How would I remove the u"string" format? For the sake of making it pretty.


[cooking, shopping, fishing] isn’t a value literal, so that won’t get printed. If you have such variables in code, then yeah you can write that, but this doesn’t describe a value by itself.

You don’t get rid of quotes any more than you get rid of the square brackets, commas, spaces in what you wrote. If you want to print it some way then what you do is you create a string based on the values that you want to display, and then you print that string

'I\'m {}, and I have a {} {}'.format('bob', 'red', 'ball')

The u and the quotes isn’t part of the data. If it was part of the data, then yes, you would want to clean up the data.


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