你好,我有这个代码:
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"
您有任何想法吗?
非常感谢您!
答案 0 :(得分:1)
要获取python列表中对象的索引,可以使用list.index
函数:
idx = list.index("dsf") # idx = 3 in your example