1. 程式人生 > >Python中檢視變數的型別,記憶體地址,所佔位元組的大小

Python中檢視變數的型別,記憶體地址,所佔位元組的大小

檢視變數的型別

#利用內建type()函式
>>> nfc=["Packers","49"]
>>> afc=["Ravens","48"]
>>> combine=zip(nfc,afc)
>>> type(combine)
<class 'zip'>

檢視變數的記憶體地址

#利用內建函式id(),是以十進位制顯示
>>> id(nfc)
2646554913160
>>> id(afc)
2646554913544

檢視變數所佔位元組的大小


>>> import sys
>>> print(sys.getsizeof(combine))
64
>>> print(sys.getsizeof(nfc))
80
>>> print(sys.getsizeof(afc))
80