日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

一起來學(xué)習(xí)一下python的數(shù)據(jù)類型_python

作者:奔跑的蝸牛—平靜從我開始 ? 更新時(shí)間: 2022-04-09 編程語言

內(nèi)置數(shù)據(jù)類型

文本類型str

數(shù)值類型int,float,complex

序列類型list,tuple,range

映射類型dict

集合類型set,frozenset

布爾類型boolean

二進(jìn)制類型bytes,bytearray,mempryview

獲取數(shù)據(jù)類型【type()】

#使用type來進(jìn)行獲取函數(shù)類型

x = 12
print('>>使用type來進(jìn)行獲取函數(shù)類型')
print(type(x))

str: 轉(zhuǎn)換為str(字符串)類型

x = 12
x_1 = str(12)
print('>>str:轉(zhuǎn)換為str(字符串)類型')
print(x_1)
print(type(x_1))

int: 轉(zhuǎn)換為int類型

y = 12.25
y_1 = int(y)
print('>> int: 轉(zhuǎn)換為int類型')
print(y_1)
print(type(y_1))

float: 轉(zhuǎn)換為float類型

z = '12.25'
z_1 = float(z)
print('>> float: 轉(zhuǎn)換為float類型')
print(z_1)
print(type(z_1))

complex:轉(zhuǎn)換為complex(復(fù)數(shù))類型

a = 1j
a_1 = complex(a)
print('>> complex:轉(zhuǎn)換為complex(復(fù)數(shù))類型')
print(a_1)
print(type(a_1))

list: 轉(zhuǎn)換為list(列表)類型

b = (1,2,3,4)
b_1 = list(b)
print('>> list: 轉(zhuǎn)換為list(列表)類型')
print(b_1)
print(type(b_1))

tuple:轉(zhuǎn)換為tuple(元組)類型

c = [1,2,3,3]
c_1 = tuple(c)
print('>> tuple:轉(zhuǎn)換為tuple(元組)類型')
print(c_1)
print(type(c_1))

range: 轉(zhuǎn)換為range類型

d = 6
d_1  = range(d)
print('>> range: 轉(zhuǎn)換為range類型')
print(d_1)
print(type(d_1))

dict: 轉(zhuǎn)換為dict(字典)類型

print('>> dict 轉(zhuǎn)換為dict(字典)類型')

e_1 = dict(a=2,b=4)
print(e_1)
print(type(e_1))

e_2 = dict([(x,1),(y,2)])
print(e_2)
print(type(e_2))

set:轉(zhuǎn)換為set(集合)類型

f = (1,2,3,3)
f_1 = set(f)
print('>> set:轉(zhuǎn)換為set(集合)類型 ')
print(f_1)
print(type(f_1))

bool: 轉(zhuǎn)換為bool(布爾)類型

g_1 = bool(x>y)
print('>>  bool: 轉(zhuǎn)換為bool(布爾)類型')
print(g_1)
print(type(g_1))
g_1 = bool(x>y)
print('>>  bool: 轉(zhuǎn)換為bool(布爾)類型')
print(g_1)
print(type(g_1))

總結(jié)

原文鏈接:https://blog.csdn.net/weixin_38931408/article/details/122689491

欄目分類
最近更新