Guest
Guest

Reputation: 515

How python interpreter determine the type of variable at runtime?

I just want to know how python's (python 2.7) interpreter is find the type of variable. Like How python Dynamic Type Behaviour internally works.

MacBook-Pro:~ neelabhsingh$ python
Python 2.7.12 (default, Jun 29 2016, 14:05:02)
>>> type(i)
<type 'int'>
>>> type(str1)
<type 'str'>
>>> testFloat = 45.67
>>> type(testFloat)
<type 'float'>

Upvotes: 3

Views: 194

Answers (1)

Alex Taylor
Alex Taylor

Reputation: 8853

In CPython 2.7 (i.e. the C language implementation of Python), there is a PyObject type. There is also a PyObject_Type function which accesses the type stored in the PyObject i.e. the object carries around type information with it.

Upvotes: 4

Related Questions