>>
> a,b,c,d=66,
6.6,
false,6
+6j>>
>
print
(type
(a),
type
(b),
type
(c),
type
(d))
<
class
'int'
>
<
class
'float'
>
<
class
'bool'
>
<
class
'complex'
>
(3)isinstance()函式與type()函式有類似的功能
>>
>
isinstance
(num,
int)
true
兩者的區別:type()不會認為子類是一種父類型別,而isinstance()會認為子類是一種父類型別
>>
classa:
pass
>>
>
class
b(a)
:pass
>>
>
isinstance
(a()
,a)true
>>
>
type
(a()
)==a
true
>>
>
isinstance
(b()
,a)true
>>
>
type
(b()
)==a
false
(4)在 python2 中是沒有布林型的,它用數字 0 表示 false,用 1 表示 true。到 python3 中,把 true 和 false 定義成關鍵字了,但它們的值還是 1 和 0,它們可以和數字相加。
>>
>1+
true
2>>
>1+
false
1
>>
>
print
("\number"
)umber
>>
>
print
(r"\number"
)\number
>>
>
str=
"i love china."
>>
>
print
(str
+"and you?"
)i love china.and you?
>>
>
print
(str*2
)i love china.i love china.
>>
> list_one=
['abc'
,6.6,66
]>>
> list_two=
[666
,'hello'
]>>
>
print
(list_one+list_two)
['abc'
,6.6,66
,666
,'hello'
]>>
>
print
(list_one*2)
['abc'
,6.6,66
,'abc'
,6.6,66
]
tuple_one=()
# 空元組
tuple_two=()
# 乙個元素,需要在元素後新增逗號
>>
> set_one=
>>
>
print
(set_one)
>>
>
dict
(a=1
,b=2
,c=3
)>>
>
dict([
('a',1
),('b',2
),('c',3
)])
Python學習 資料型別
usr bin python coding utf 8 filename datatype.py python有四種型別的數 1.整型 a 2 print a 2.長整型 b 123456789 print b 3.浮點數 c 3.2e2 print c 4.複數 複數為實數的推廣,它使任一多項式都...
Python 簡單資料型別
數字 整數 int,long 整數在3版本沒有大小長度分別,記憶體決定整數最大長度 浮點數 float 無窮小數會做精度處理,四捨五入,只要有小數點就是浮點型 布林 bool 非空 none 非0為真,0或空為假 複數 complex 複數的標誌為虛部以大寫 j 或小寫 j 結尾 字串 表達方式 單...
python資料型別簡單整理
現在只是一部分資料型別的簡單整理,後續還會更新 這裡來乙個示例,後續介紹的就不給出示例了,不然篇幅太長影響閱讀 s 1,3,5,7,5,9,3,7,9 x in s 3 in s true 2 in s false x not in s 3 not in s false 2 not in s tru...