Declare different types of variables; print their types, ids and variables in Python.
There are two inbuilt functions are using in the program:
- type() - its returns the data type of the variable/object.
- id() - it returns the unique identification number (id) of created object/variable.
-
Program:
Output
Numbers --------------------------------- <class 'int'> 10455328 10 <class 'float'> 139852163465696 23.7 <class 'complex'> 139852162869456 (2+6j) Text --------------------------------- <class 'str'> 139852162670976 h <class 'str'> 139852162670976 h <class 'str'> 139852162911512 hello <class 'str'> 139852162911512 hello Boolean --------------------------------- <class 'bool'> 10348608 True Function --------------------------------- <class 'function'> 139852163226616 I am Function Objects --------------------------------- <class '__main__.Demo'> 139852162234016 Hi Collections --------------------------------- <class 'list'> 139852162259208 [1, 2, 3] <class 'list'> 139852162261256 [] <class 'tuple'> 139852162244752 (1, 2, 3) <class 'tuple'> 139852182028360 () <class 'tuple'> 139852162244968 (1, 2, 3) <class 'set'> 139852163034472 {1, 2, 3} <class 'dict'> 139852163024776 {} <class 'dict'> 139852163024584 {'id': 1, 'name': 'pooja'}need an explanation for this answer? contact us directly to get an explanation for this answer