Python programming- List extend() and append()
Blogpump中想在list中添加一个嵌套的list为其子项,但是调用extend发现总是结果不对,才发现原来extend和append的调用有如此的差别。
1. list extend (扩展) 与 append (追加) 的差别
>>>li=['a','b']
>>>li.extend(['c','d'])
>>>li
['a', 'b', 'c', 'd']
>>>li.append(['e','f'])
>>>li
['a', 'b', 'c', 'd',['e','f']]
2. 搜索 搜索 list
>>>li.index(’b')
>>>li
1
3. List 运算符+ 和 ×
>>> li = ['a', 'b']
>>> li = li + ['example', 'new']
>>> li
['a', 'b', 'example', 'new']
>>> li += ['two']
>>> li
['a', 'b', 'example', 'new', 'two']
>>> li = [1, 2] * 3
>>> li
[1, 2, 1, 2, 1, 2]
4.何谓 Python 中的 True
·0为false; 其它所有数值皆为 true。
·空串 ("") 为false; 其它所有字符串皆为 true。
·空list ([])为false; 其它所有字符串皆为 true。
·空 tuple (()) 为false; 其它所有字符串皆为 true。
·空 dictionary ({}) 为false; 其它所有字符串皆为 true。
此篇为转载:http://www.blogjava.net/yglwxl/archive/2009/05/14/270562.html
Related posts:
- Python用SGMLParser抓取网页连接的改进
- Python Programming – Sqlite for data persistence
- Core Python Programming(1) - Basic
- A rough guide for wxWidgets programming
- Eclipse SDK + PyDev = Python IDE
- Python 3 简介
- Python HTML Parser Performance
- BlogPump: Blog Post Client with Web Crawler(1) – big picture
- Book: Cross-Platform GUI Programming with wxWidgets (Bruce Perens)(含中英文版本下载地址)
- 开始Python — Dictionary














