Specifing arguments type for a function
Diez B. Roggisch
deets at nospam.web.de
Tue Jun 20 06:57:22 EDT 2006
> What about
> def f(arg):
> if type(arg)=='list':
> #do something
- list is a string in your code - which wont work:
>>> type() == 'list'
It needs to be list w/o quotes.
- you won't get sublclasses of list:
>>> class Foo(list):
>>> type(Foo()) == list
So better use isinstance, as I already mentioned.
More information about the Python-list