python數據類型8種?>>> type(1 1.0)
<class 'float'>
>>> type(4/2)
<class 'float'>
>>> type(24//2)
<class 'int'>
>>> 4/2
2.0
>>> 4//2
2
>>>
>>> 1//2
0
,今天小編就來說說關于python數據類型8種?下面更多詳細答案一起來看看吧!
>>> type(1 1.0)
<class 'float'>
>>> type(4/2)
<class 'float'>
>>> type(24//2)
<class 'int'>
>>> 4/2
2.0
>>> 4//2
2
>>>
>>> 1//2
0
>>> 0b10
2
>>> 0o10
8
>>> 0x10
16
>>> bin(0b100)
'0b100'
>>> oct(0o100)
'0o100'
>>> int(100)
100
>>> hex(0xf)
'0xf'
>>> type(True)
<class 'bool'>
>>> type(False)
<class 'bool'>
>>> int(False)
0
>>> int(True)
1
>>> bool(0) # 0 表示false
False
>>> bool(1)
True
>>> bool(-1)
True
>>> bool(2)
True
>>> bool(0x0)
False
>>> bool("")
False
>>> bool([])
False
>>> bool({})
False
>>> bool(())
False
>>> bool(None)
False
>>> 36j
36j
>>> type(36j)
<class 'complex'>
>>> type('2')
<class 'str'>
>>> type(1)
<class 'int'>
>>> "it's good"
"it's good"
>>> 'it\'s good'
"it's good"
>>> """
... ni hao
... hello
... hi"""
'\nni hao\nhello\nhi'
>>> """ nihao \n hi"""
' nihao \n hi'
>>> print(""" nihao \n hi""")
nihao
hi
>>> 'ni\
... hao'
'nihao'
\n 換行,\t 橫向制表符, \r 回車
\' 單引号
>>> print("hello \n world")
hello
world
>>> print("hello \\n world")
hello \n world
>>> print("c:\north\no.py")
c:
orth
o.py
>>> print("c:\\north\\no.py")
c:\north\no.py
>>> print(r"c:\\north\\no.py")
c:\\north\\no.py
>>> "hello" "world"
'helloworld'
>>> "hello"*2
'hellohello'
>>> "hello"[0]
'h'
>>> "hello"[1]
'e'
>>> "hello"[-1]
'o'
>>> "hello world"[0:5]
'hello'
>>> "hello world"[0:-3]
'hello wo'
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!