小编Edi*_*lan的帖子

将字符串转换为负数

我需要从字符串类型转换为数字

list = ["-5","4","-3","variable"]  # Input

list = [-5,4,-3,"variable"]        # epected output
Run Code Online (Sandbox Code Playgroud)

我在转换负数时遇到问题

list[0]=int(list[0])
Run Code Online (Sandbox Code Playgroud)

ValueError:int() 的无效文字,基数为 10:'-5'

python python-2.7

2
推荐指数
3
解决办法
3万
查看次数

标签 统计

python ×1

python-2.7 ×1