码迷,mamicode.com
首页 > 移动开发 > 详细

python List有关append&extend

时间:2015-04-26 16:37:45      阅读:141      评论: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)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!