gpt4 book ai didi

python - 类型错误 : unsupported operand type(s) for +: 'float' and 'tuple'

转载 作者:太空宇宙 更新时间:2023-11-04 10:41:45 24 4
gpt4 key购买 nike

我有这个元组:

results[0]

#0 tuple(7)
[0] => int(375851)
[1] => str(26) "joaquina gisela dos sanots"
[2] => str(10) "1963-11-24"
[3] => int(378129)
[4] => str(26) "Joaquina Gisela Dos Santos"
[5] => str(10) "1963-11-24"
[6] => float(1.0)

我想将这个 float 添加到索引 0:

lev_name = float(0.92) 

预期输出:

#0 tuple(8) 
[0] => float(0.92)
[1] => int(375851)
[2] => str(26) "joaquina gisela dos sanots"
[3] => str(10) "1963-11-24"
[4] => int(378129)
[5] => str(26) "Joaquina Gisela Dos Santos"
[6] => str(10) "1963-11-24"
[7] => float(1.0)

我正在尝试:

results = lev_name + results[0] 

我该怎么做?

最佳答案

试试这个

results = (lev_name,) + results

你不能添加到索引 0. 因为元组是不可变的.. :)

关于python - 类型错误 : unsupported operand type(s) for +: 'float' and 'tuple' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20241465/

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