python List有关append&extend

>>> 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。
posted @ 2015-04-26 15:43  Mr.Autumn  阅读(204)  评论(0)    收藏  举报