ITPub博客

首页 > IT职业 > IT图书 > python如何取数组后几位?

python如何取数组后几位?

IT图书 作者:flf811124 时间:2021-09-11 10:17:23 0 删除 编辑

python中去数组后几位的方法:

一维数组输出最后一位的方法:

output = [1,2,3]
          
print(output[-1])

输出结果:

3

输出后两位:

output = [1,2,3]
          
print(output[-2:])

输出结果:

[2, 3]

二维数组输出最后一位:

output = [[1,2,3],
          [4,5,6],
          [2, 5, 6]]
print(output[1][-1])

输出结果:

6

更多Python知识请关注Python视频教程栏目。

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

上一篇: Django中的ORM之查
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    103
  • 访问量
    694