python列表使用实例
  Vep0yEIxOBWI 2023年11月17日 18 0


#!/usr/bin/python

-- coding: UTF-8 --

#list
#新建列表
testList=[10086,'中国移动',[1,2,4,5]]

#访问列表长度
print len(testList)
#到列表结尾
print testList[1:]
#向列表添加元素
testList.append('i\'m new here!')

print len(testList)
print testList[-1]
#弹出列表的最后一个元素
print testList.pop(1)
print len(testList)
print testList
#list comprehension
#后面有介绍,暂时掠过
matrix = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
print matrix
print matrix[1]
col2 = [row[1] for row in matrix]#get a column from a matrix
print col2
col2even = [row[1] for row in matrix if row[1] % 2 == 0]#filter odd item
print col2even

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月17日 0

暂无评论

推荐阅读
  2Fnpj8K6xSCR   2024年05月17日   101   0   0 Python
  xKQN3Agd2ZMK   2024年05月17日   70   0   0 Python
  fwjWaDlWXE4h   2024年05月17日   38   0   0 Python
Vep0yEIxOBWI
作者其他文章 更多

2023-12-04

2023-11-25

2023-11-24

2023-11-22

2023-11-15