python中有三種數值型別:
數值型別變數會在賦值時自動建立:
示例:
a =
6# int
b =8.8
# float
c =6j
# complex
要驗證python 物件的型別,可使用type()
函式:
示例:
print
(type
(a))
print
(type
(b))
print
(type
(c))
整型,是乙個整數,正或負,沒有小數,無限長。
示例:
a =
8b =
4567891234576725432
c =-
531431412
print
(type
(a))
print
(type
(b))
print
(type
(c))
浮點數,包含乙個或多個小數,可以是正數或負數。
示例:
a =
8.88
b =5.0
c =-
4324.432
print
(type
(a))
print
(type
(b))
print
(type
(c))
浮點數也可以是科學計數法表示的數字,用「e」表示10的冪。
示例:
a =
555e6
b =35e2
c =-
678.8e32
print
(type
(a))
print
(type
(b))
print
(type
(c))
複數的虛數部分用「j」表示:
示例:
a =7+
9jb =
3jc =-8j
print
(type
(a))
print
(type
(b))
print
(type
(c))
Python 數值型別
1 變數命名規則 推薦 使用 具有固定含義的英語單詞縮寫,srv server skt socket,一般以posix命名規則為主 駝峰命名法 大駝峰 名稱以單詞自動連線,且每個單詞首字母均大寫 小駝峰 類似大駝峰,但每乙個字母小寫 posix寫法 多個單詞用下劃線連線 單詞全小寫 my first...
Python 數值型別
python中有三種數值型別 數值型別變數會在賦值時自動建立 示例 a 6 int b 8.8 float c 6j complex要驗證python 物件的型別,可使用type 函式 示例 print type a print type b print type c 整型,是乙個整數,正或負,沒有...
python的數值型別 Python 數值型別
python的數值型別 python中有三種數值型別 int 整型 float 浮點型 complex 複數 數值型別變數會在賦值時自動建立 示例 a 6 int b 8.8 float c 6j complex 要驗證python 物件的型別,可使用type 函式 示例 print type a ...