Lesson Number One


#1


https://www.codecademy.com/courses/python-beginner-en-qzsCL/0/1?curriculum_id=4f89dab3d788890003000096

Why does "name": "Lloyd" work, and "name': ["Lloyd"] not work? I understand that a dictionary can contain a string. I don't understand why ["Lloyd"] can't be a list. Does a list need to have more than one item in it?

This works:
lloyd = {
"name": "Lloyd",
"homework": [],
"quizzes": [],
"tests": [],

This does not work:
lloyd = {
"name": ["Lloyd"],
"homework": [],
"quizzes": [],
"tests": [],


Replace this line with your code.


#2

Sorry, I see that my indents were removed. There really are indents in my code.


#3

Hi @lithezebra1 ,

It is important to format posted code. See How do I format code in my posts?.

The reason that the "name" key should refer to a string rather than to a list containing a string, is that in this class, each student will always have only one name. Although we can have a list with a single item, or even have a list that contains no items, it is more convenient to use a string instead of a list of strings, in a situation where we are always going to need only one string.


#4

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