gpt4 book ai didi

Python 将整数列表转换为整数

转载 作者:行者123 更新时间:2023-12-01 06:41:13 25 4
gpt4 key购买 nike

我如何转换为前。 x = [0, 25, 303, 4]到整数,而不是列表,而不在开头丢失 0?我尝试过 print(int(''.join(map(str,x))))但输出没有 0。

必须使用“返回”而不是“打印”来完成 - 我必须将其保存到 .txt 文件中。

我的预期输出是“0253034”。

最佳答案

如果您只想连接列表,您可以这样做:

lst = [0, 25,303,4] 
for i in lst:
print(i, end="")

输出:

0253034

def convertor(lis):
a=''
for i in lis:
a=a+str(i)
return a

lst = [0, 25,303,4]
print(convertor(lst))

关于Python 将整数列表转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59449512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com