Python 官方文档:入门教程 => 点击学习
python中str与int类型的相互转换 1. str转换成int 方法:使用int()函数 # Python中str转换成int a='12' b=int(a) # 转换成1
1. str转换成int
方法:使用int()函数
# Python中str转换成int a='12' b=int(a) # 转换成10进制str对应的int c=int(a,16) # 转换成16进制str对应的int print(type(b)) # print(b) # 12 print(type(c)) # print(c) # 18
3. int转换成str
方法:使用str()函数
# python中int转换成str d=12 e=str(d) # 转换成int对应10进制的str f=hex(d) # 转换成int对应16进制的str print(type(e)) # print(e) # 12 print(type(f)) # print(f) # 0xc
来源地址:https://blog.csdn.net/weixin_43772972/article/details/126690056
--结束END--
本文标题: python中str与int类型的相互转换
本文链接: https://www.lsjlt.com/news/428652.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0