Cameron Hiruta Cameron Hiruta -4 years ago 139
Python Question

Why does python give me a TypeError for this function? (new to coding)

I'm new to coding and not sure why the list is being typed as a tuple.

Answer Source

You've used the same name, list, for both a built-in type and a local variable. Don't re-use the built-in names. Quoting PEP-8:

If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than clss . (Perhaps better is to avoid such clashes by using a synonym.)


def funct2(list_):
    if type(list_) == list:

Or, better:

def funct2(list_):
    if isinstance(list_, list):
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download