时间:2022-10-22 13:57:29 | 栏目:Python代码 | 点击:次
文本类型:str
数值类型: int
,float
,complex
序列类型:list
,tuple
,range
映射类型: dict
集合类型: set
,frozenset
布尔类型: boolean
二进制类型: bytes
,bytearray
,mempryview
#使用type来进行获取函数类型
x = 12 print('>>使用type来进行获取函数类型') print(type(x))
x = 12 x_1 = str(12) print('>>str:转换为str(字符串)类型') print(x_1) print(type(x_1))
y = 12.25 y_1 = int(y) print('>> int: 转换为int类型') print(y_1) print(type(y_1))
z = '12.25' z_1 = float(z) print('>> float: 转换为float类型') print(z_1) print(type(z_1))
a = 1j a_1 = complex(a) print('>> complex:转换为complex(复数)类型') print(a_1) print(type(a_1))
b = (1,2,3,4) b_1 = list(b) print('>> list: 转换为list(列表)类型') print(b_1) print(type(b_1))
c = [1,2,3,3] c_1 = tuple(c) print('>> tuple:转换为tuple(元组)类型') print(c_1) print(type(c_1))
d = 6 d_1 = range(d) print('>> range: 转换为range类型') print(d_1) print(type(d_1))
print('>> dict 转换为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))
f = (1,2,3,3) f_1 = set(f) print('>> set:转换为set(集合)类型 ') print(f_1) print(type(f_1))
g_1 = bool(x>y) print('>> bool: 转换为bool(布尔)类型') print(g_1) print(type(g_1)) g_1 = bool(x>y) print('>> bool: 转换为bool(布尔)类型') print(g_1) print(type(g_1))