Python 數值型別
Python 中的數值型別是整數資料型別。它包括整數、浮點數、複數等。複數包括實部和虛部。也包括十六進位制和八進位制型別。
Python int 資料型別
數值型別包括 int 資料型別 −
a = 5 print("Integer = ",a) print("Type = ",type(a))
輸出
Integer = 5 Type = <class 'int'>
Python float 資料型別
數值型別包括 float 資料型別 −
示例
a = 7E2 print("Float = ",a) print("Type = ",type(a))
輸出
Float = 700.0 Type = <class 'float'>
Python complex 資料型別
數值型別包括具有實部和虛部的 complex 資料型別 −
示例
a = 2.75+3.15j print("Complex = ",a) print("Type = ",type(a))
輸出
Complex = (2.75+3.15j) Type = <class 'complex'>
Python 十六進位制型別
要表示八進位制型別(基數 16),請新增一個字首 0x −
示例
a = 0x12 print("Hexadecimal = ",a) print("Type = ",type(a))
輸出
Hexadecimal = 18 Type = <class 'int'>
Python 八進位制型別
要表示八進位制型別(基數 8),請新增一個字首 0(零)−
a = 0O20 print("Octal = ",a) print("Type = ",type(a))
輸出
Octal = 16 Type = <class 'int'>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP