You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Object type comparisons should always use isinstance() instead
of comparing types directly.
Yes: if isinstance(obj, int):
No: if type(obj) is type(1):
When checking if an object is a string, keep in mind that it might be a
unicode string too! In Python 2.3, str and unicode have a common base
class, basestring, so you can do:
if isinstance(obj, basestring):
People, including me, tend to import the types module and do something like "type(XXX) is types.IntType".
Comparing types directly should trigger an error.
The text was updated successfully, but these errors were encountered:
According to PEP8,
People, including me, tend to import the types module and do something like "type(XXX) is types.IntType".
Comparing types directly should trigger an error.
The text was updated successfully, but these errors were encountered: