Python programming- List extend() and append()

Blogpump中想在中添加一个嵌套的为其子项,但是调用发现总是结果不对,才发现原来的调用有如此的差别。

1. (扩展) 与 (追加) 的差别
>>>li=['a','b']
>>>li.(['c','d'])
>>>li
['a', 'b', 'c', 'd']
>>>li.(['e','f'])
>>>li
['a', 'b', 'c', 'd',['e','f']]

2. 搜索 搜索
>>>li.index(’b')
>>>li
1
3. 运算符+ 和 ×

>>> 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.何谓 中的 True

·0为false;   其它所有数值皆为 true。

·空串 ("") 为false;  其它所有字符串皆为 true。

·空 ([])为false;  其它所有字符串皆为 true。

·空 tuple (()) 为false;  其它所有字符串皆为 true。

·空 dictionary ({}) 为false;  其它所有字符串皆为 true。

此篇为转载:http://www.blogjava.net/yglwxl/archive/2009/05/14/270562.html

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Related posts:

  1. Python用SGMLParser抓取网页连接的改进
  2. Python Programming – Sqlite for data persistence
  3. Core Python Programming(1) - Basic
  4. A rough guide for wxWidgets programming
  5. Eclipse SDK + PyDev = Python IDE
  6. Python 3 简介
  7. Python HTML Parser Performance
  8. BlogPump: Blog Post Client with Web Crawler(1) – big picture
  9. Book: Cross-Platform GUI Programming with wxWidgets (Bruce Perens)(含中英文版本下载地址)
  10. 开始Python — Dictionary

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Contact us

Admin: Bryan Wu