2.2 features
Guido van Rossum
guido at python.org
Thu Jul 26 10:09:36 EDT 2001
"Nick Perkins" <nperkins7 at home.com> writes:
> Here's a nice little use of type/class unification:
>
> instead of using:
> if type(x) is type(0):
>
> we can use:
> if type(x) is int:
>
> or, for type checking..
>
> assert type(num) is int
> assert type(msg) is str
>
> ( I assume the use of 'is', rather than '==', is acceptable here )
Yes, 'is' is right. But you should never use this; instead, you
should use
assert isinstance(num, int)
assert isinstance(msg, str)
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list