10.For your hobbies


#1




The code runs normally,but I want to know why there is an "u" before the users in my output.What does that mean?Here is what happend in the interpreter:
Enter your name: hua
Enter your name: shao
Enter your name: jie
[u'hua', u'shao', u'jie']
None


hobbies = []

# Add your code below!
for i in range(3):
    user = raw_input("Enter your name: ")
    hobbies.append(user)
print hobbies


#2

something about codecademy causes raw_input stores the strings as unicode rather then string

so the u is of unicode, simply cast to a string:

str(raw_input("input: "))

#3

Thank you,now I got it.


#4

@stetim94's solution is probably the best way to handle this. However, here's an alternative that can also output a list of unicode or str objects ...

print("\n".join(hobbies))

#5

true, but in most cases raw_input would give you strings, not uni-code


#6

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