'tent' vs "tent" in a list[ ]

backpack = ['xylophone', 'dagger', 'tent', 'bread loaf']

del backpack[1]
print backpack

the above gives me this error:

Traceback (most recent call last):

File “python”, line 4, in

TypeError: ‘builtin_function_or_method’ object has no attribute ‘getitem

BUT this runs fine : what is the difference between ’ and " in the list?

beatles = ["john","paul","george","ringo","stuart"]
print beatles


this difference is irrelevant, the difference you should be looking at is square brackets vs parentheses. using square brackets like you did here:


throws an error because using square brackets will try to use tent as key from remove (treating remove as dictionary)

using parentheses, will make it a method call, that is where the difference is


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