python raw_input() 用來獲取控制台的輸入。
raw_input() 將所有輸入作為字串看待,返回字串型別。
raw_input
([prompt]
)
>>
>a =
raw_input
("input:"
)input
:123
>>
>
type
(a)<
type
'str'
>
# 字串
>>
> a =
raw_input
("input:"
)input
:runoob
>>
>
type
(a)<
type
'str'
>
# 字串
>>
>
>>
>a =
input
("input:"
)input
:123
# 輸入整數
>>
>
type
(a)<
type
'int'
>
# 整型
>>
> a =
input
("input:"
)input
:"runoob"
# 正確,字串表示式
>>
>
type
(a)<
type
'str'
>
# 字串
>>
> a =
input
("input:"
)input
:runoob # 報錯,不是表示式
traceback (most recent call last)
: file ""
, line 1,in
file ""
, line 1,in
nameerror: name 'runoob'
isnot defined
<
type
'str'
>
python內建數值處理函式
absdivmodfloathexintmaxminoctpowround作為python內建數值處理函式。絕對值函式,返回當前數值的絕對值。abs 5 5 abs 9.3 9.3求商和餘數,將兩個 非複數 作為實參,返回商和餘數。等同於 a b,a b divmod 4 2 2,0 divmod ...
Python內建函式系列之數值相關函式
可以是整數,浮點數或者複數。返回乙個數的絕對值。若引數是複數則返回模。abs 1 1 abs 1 1 abs 1.23 1.23 abs 1.23 1.23 abs 2 2j 2.8284271247461903乙個整型資料。返回其二進位制字串。bin 1 0b1 bin 8 0b1000 bin ...
Python基礎學習數值運算之內置函式
1 abs num 返回num的絕對值 2 coerce num1,num2 將num1和num2轉換為同一型別,然後以乙個無級的形式返回 3 divmod num1,num2 除法取餘運算的結合。返回乙個元組 num1 num2,num1 num2 對浮點型和複數的商進行下捨入 複數僅取實數部分的...