2016-08-24 82 views
3

我只想知道python的(python 2.7)解釋器是找到變量的類型。像Python動態類型行爲如何在內部工作。python解釋器如何在運行時確定變量的類型?

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'> 
+0

哪個特定的實現? CPython 2.7或3.4?或其他; PyPy,Jython,IronPython等? –

+0

@PeterWood,Python 2.7.12 – Guest

回答

4

在CPython 2.7(即Python的C語言實現)中,有一個PyObject type。還有一個PyObject_Type函數,它訪問存儲在PyObject中的類型,即該對象帶有類型信息。

相關問題