2.python数据类型

数据类型

内置数据类型

  1. 文本类型: str
  2. 数值类型: int,float,complex
  3. 序列类型: list,tuple,range
  4. 映射类型: dict
  5. 集合类型: set, frozenset
  6. 布尔类型: boolean
  7. 二进制类型: bytes,bytearray,mempryview

获取数据类型【type()】

#使用type来进行获取函数类型

x = 12
print('>>使用type来进行获取函数类型')
print(type(x))

str: 转换为str(字符串)类型

x = 12
x_1 = str(12)
print('>>str:转换为str(字符串)类型')
print(x_1)
print(type(x_1))

int: 转换为int类型

y = 12.25
y_1 = int(y)
print('>> int: 转换为int类型')
print(y_1)
print(type(y_1))

float: 转换为float类型

z = '12.25'
z_1 = float(z)
print('>> float: 转换为float类型')
print(z_1)
print(type(z_1))

complex:转换为complex(复数)类型

a = 1j
a_1 = complex(a)
print('>> complex:转换为complex(复数)类型')
print(a_1)
print(type(a_1))

list: 转换为list(列表)类型

b = (1,2,3,4)
b_1 = list(b)
print('>> list: 转换为list(列表)类型')
print(b_1)
print(type(b_1))

tuple:转换为tuple(元组)类型

c = [1,2,3,3]
c_1 = tuple(c)
print('>> tuple:转换为tuple(元组)类型')
print(c_1)
print(type(c_1))

range: 转换为range类型

d = 6
d_1  = range(d)
print('>> range: 转换为range类型')
print(d_1)
print(type(d_1))

dict: 转换为dict(字典)类型

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))

set:转换为set(集合)类型

f = (1,2,3,3)
f_1 = set(f)
print('>> set:转换为set(集合)类型 ')
print(f_1)
print(type(f_1))

bool: 转换为bool(布尔)类型

g_1 = bool(x>y)
print('>>  bool: 转换为bool(布尔)类型')
print(g_1)
print(type(g_1))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奔跑的蜗牛—平静从我开始

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值