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

更新日期:2022-8-11

3K+ 瀏覽量

開啟您的 職業生涯

完成課程,獲得認證

開始吧
廣告
© . All rights reserved.