首页 > 移动平台 > 详细

python List有关append&extend

时间:2015-04-26 16:37:26      阅读:335      评论:0      收藏:0      [点我收藏+]
>>> mylist = [a, b]
>>> mylist.append([c,d])
>>> mylist
[a, b, [c, d]]
>>> mylist.extend([e,f])
>>> mylist
[a, b, [c, d], e, f]
>>> mylist.index(b)
1
>>> mylist.index([c,d])
2
List运算中的 + 和 *
>>> mylist
[a, b, [c, d], e, f]
>>> mylist = mylist + [g,h]
>>> mylist
[a, b, [c, d], e, f, g, h]
>>> mylist += [i]
>>> mylist
[a, b, [c, d], e, f, g, h, i]
>>> yourlist = [1,2,3]
>>> yourlist = yourlist * 3
>>> yourlist
[1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> 

何谓 Python 中的 True:

  • 0为false;   其它所有数值皆为 true。
  • 空串 ("") 为false;  其它所有字符串皆为 true。
  • 空list ([])为false;  其它所有字符串皆为 true。
  • 空 tuple (()) 为false;  其它所有字符串皆为 true。
  • 空 dictionary ({}) 为false;  其它所有字符串皆为 true。

python List有关append&extend

原文:http://www.cnblogs.com/haohonglee/p/4457860.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!