<分区>
numbers = "51-52"
for st in numbers:
part = st.split("-")
print(part)
到目前为止,这是我的代码。
我的结果:['5']['1']['', '']['5']['2']
预期:['51']['52']
<分区>
numbers = "51-52"
for st in numbers:
part = st.split("-")
print(part)
到目前为止,这是我的代码。
我的结果:['5']['1']['', '']['5']['2']
预期:['51']['52']
最佳答案
numbers = "51-52"
part = [int(x) for x in numbers.split("-")]
print(part)
关于python - 如何拆分字符串并转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37515372/