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


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

del backpack[1]
backpack.remove['tent']
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"]
beatles.remove("stuart")
print beatles

#2

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

remove['tent']

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


#3

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