gpt4 book ai didi

python - 在元组中查找字符串的索引

转载 作者:IT老高 更新时间:2023-10-28 22:18:05 26 4
gpt4 key购买 nike

Tup = ('string1','string2','string3')

我的程序返回 string2 如何在 Tup 中获取它的索引?

最佳答案

>>> tup.index('string2')
1

请注意,index() 方法只是在 2.6 及更高版本中为元组添加的。

关于python - 在元组中查找字符串的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4021154/

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