gpt4 book ai didi

python - 返回嵌套列表中的项目(python)

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

我正在做 Python 基础编程类(class)的实验,但我不知道如何在另一个列表中返回一个列表中的数字。
我应该返回带有“一个表达式且没有括号”的 4

[1,[2,[3,4]]]

有什么想法吗?到目前为止,我所得到的只是返回 [2,[3,4]] 而我无法弄清楚除此之外的任何事情。

最佳答案

>>> a = [1,[2,[3,4]]]
>>> a[1]
[2, [3, 4]]
>>> a[1][1]
[3, 4]
>>> a[1][1][1]
4
>>>

关于python - 返回嵌套列表中的项目(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7584653/

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