variables - Where is a list of all of python's `__builtin__` datatypes? -
i'm using comparisons like:
if type( self.__dict__[ key ] ) str \ or type( self.__dict__[ key ] ) set \ or type( self.__dict__[ key ] ) dict \ or type( self.__dict__[ key ] ) list \ or type( self.__dict__[ key ] ) tuple \ or type( self.__dict__[ key ] ) int \ or type( self.__dict__[ key ] ) float:
i've once discovered, i've missed bool type:
or type( self.__dict__[ key ] ) bool \
,
okay - wondered other types missed?
- docs.python.org - there no table types...
i've started googling:
-
python has many native datatypes. here important ones:
- booleans either true or false.
- numbers can integers (1 , 2), floats (1.1 , 1.2), fractions (1/2 , 2/3), or complex numbers.
- strings sequences of unicode characters, e.g. html document.
- bytes , byte arrays, e.g. jpeg image file.
- lists ordered sequences of values.
- tuples ordered, immutable sequences of values.
- sets unordered bags of values.
- dictionaries unordered bags of key-value pairs.
why everywhere people talking many types, can't find list of of them? it's important ones
you can iterate on __builtin__
's __dict__
, , use isinstance
see if class:
builtins = [e (name, e) in __builtin__.__dict__.items() if isinstance(e, type) , e not object] >>> builtins [bytearray, indexerror, syntaxerror, unicode, unicodedecodeerror, memoryview, nameerror, byteswarning, dict' systemexit ...
(note @user2357112 pointed out in excellent comment, explicitly excluding object
, not useful.)
note isinstance
can take tuple second argument, can use instead of series of if
s. consequently, can write things so:
builtins = tuple([e (name, e) in __builtin__.__dict__.items() if isinstance(e, type) , not isinstance(object, e)]) >>> isinstance({}, builtin_types) true
Comments
Post a Comment