ITPub博客

首页 > IT职业 > IT职场 > 在Python中如何获取元素在数组中的索引号?

在Python中如何获取元素在数组中的索引号?

IT职场 作者:zhjhome 时间:2021-09-11 10:37:58 0 删除 编辑

在Python中如何获取元素在数组中的索引号?

具体如下:

这里python是通过index方法获取索引号的

li = ['a', 'b', 'new', 'D', 'z', 'example', 'new', 'two', 'elements']
print li.index("example")
print li.index("new")
print li.index("z")
print "c" in li

运行结果如下:

5
2
4
False

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2530/viewspace-2837477/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    102
  • 访问量
    950