gpt4 book ai didi

python - 开始于 python 中的列表?

转载 作者:行者123 更新时间:2023-11-28 22:49:21 24 4
gpt4 key购买 nike

在 python 中是否有等效于列表的开头?

我想知道列表 a 是否以列表 b 开头。喜欢

len(a) >= len(b) and a[:len(b)] == b ?

最佳答案

你可以只写a[:len(b)] == b

如果 len(b) > len(a),则不会出现错误。

关于python - 开始于 python 中的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23905380/

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