Cameron Hiruta Cameron Hiruta - 1 month ago 5x
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.


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):