Python类型转换语句示例:10个常见用法
- 将整数转换为浮点数:float(5) \n2. 将浮点数转换为整数:int(3.14) \n3. 将字符串转换为整数:int("10") \n4. 将整数转换为字符串:str(100) \n5. 将布尔值转换为整数:int(True) \n6. 将整数转换为布尔值:bool(0) \n7. 将列表转换为元组:tuple([1, 2, 3]) \n8. 将元组转换为列表:list((1, 2, 3)) \n9. 将字典转换为字符串:str({"name": "John", "age": 25}) \n10. 将字符串转换为字典:dict('{"name": "John", "age": 25}')
原文地址: https://www.cveoy.top/t/topic/px0P 著作权归作者所有。请勿转载和采集!