Python 在元组中查找字符串的索引
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4021154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:53:52 来源:igfitidea点击:
Finding the index of a string in a tuple
提问by rectangletangle
Tup = ('string1','string2','string3')
My program returned string2how do I get it's index within Tup?
我的程序返回string2如何在Tup 中获取它的索引?
采纳答案by mechanical_meat
>>> tup.index('string2')
1
Note that the index()method has only just been added for tuples in versions 2.6 and better.
请注意,该index()方法仅在 2.6 及更高版本中为元组添加。

