如何获得数组的索引?

时间:2019-05-19 22:29:49

标签: python python-3.x

你好,我有这个代码:

a = ["aze", "1213", "fdpe"]
a+= ["dsf"] # I would want to get the index of this writting
something which allows to get the index because sometimes
it can be a variable and I cannot to know the value of the variable
a+= ["fsdfsd"]

我想获取此索引,例如,我想获取3,因为在我的cas a[3] = "dsf"

您有任何想法吗?

非常感谢您!

1 个答案:

答案 0 :(得分:1)

要获取python列表中对象的索引,可以使用list.index函数:

idx = list.index("dsf")   # idx = 3 in your example
相关问题