python Êý×飬ÐòÁУ¬×ֵ䣬ÁÐ±í£¬Ðò±í£¬Ôª×棨tuple£©
python ûÓÐÊý×éµÄÊý¾Ý½á¹¹
#list ÐòÁÐ
sample_list = [1,2,3,'abc']
#dictionary ×Öµä
sample_dic = {"key":value, 2:3}
#tuple Ö»¶ÁµÄÐòÁÐ
sample_tuple = (1,3,"ab")
Ðò±í
Ðò±íÓÉһϵÁÐÖµÓöººÅ·Ö¸ô¶ø³É
Ðò±íÓë×Ö·û´®Ò»ÑùÊDz»¿É±äµÄ£º²»ÔÊÐí¶ÔÐò±íµÄijһÏֵ
×Öµä
¹ØÁªÊý×é
Óë×Ö·û´®²»Í¬µÄÊÇÁбíÊǿɱäµÄ£¬¿ÉÒÔÐÞ¸ÄÁбíµÄÿ¸öÔªËØ
¿ÉÒÔ½¨Á¢Ç¶Ì×ÁÐ±í£¨±íµÄÔªËØÒ²ÊÇÁÐ±í£©
ÁÐ±í·½·¨
ÁбíÊý¾ÝÀàÐÍ»¹ÓÐÆäËüһЩ·½·¨¡£ÏÂÃæÊÇÁбí¶ÔÏóµÄËùÓз½·¨£º
• insert(i, x) ----
ÔÚÖ¸¶¨Î»ÖòåÈëÒ»Ïî¡£µÚÒ»×Ô±äÁ¿ÊÇÒªÔÚÄÄÒ»¸öÔªËØÇ°Ãæ²åÈ룬ÓÃϱê±íʾ¡£ÀýÈ磬a.insert(0,
x)ÔÚÁбíÇ°Ãæ²åÈ룬a.insert(len(a), x)µÈ¼ÛÓÚa.append(x) ¡£
• append(x) ---- µÈ¼ÛÓÚa.insert(len(a), x)
• index(x) ---- ÔÚÁбíÖвéÕÒÖµx È»ºó·µ»ØµÚÒ»¸öֵΪx µÄÔªËصÄϱꡣûÓÐÕÒµ½Ê±³ö´í¡£
• remove(x) ---- ´ÓÁбíÖÐɾȥµÚÒ»¸öֵΪx µÄÔªËØ£¬ÕÒ²»µ½Ê±³ö´í¡£
• sort() ---- ¶ÔÁбíÔªËØÔÚÔλÅÅÐò¡£×¢ÒâÕâ¸ö·½·¨¸Ä±äÁÐ±í£¬¶ø²»ÊÇ·µ»ØÅÅÐòºóµÄÁÐ±í¡£
• reverse() ---- °ÑÁбíÔªËØ·´Ðò¡£¸Ä±äÁÐ±í¡£
• count(x) ---- ·µ»Øx ÔÚÁбíÖгöÏֵĴÎÊý¡£
ÄÚÖú¯Êý
filter()
filter(º¯Êý, ÐòÁÐ) -
·µ»ØÒ»¸öÐòÁУ¨¾¡¿ÉÄÜÓëÔÀ´Í¬ÀàÐÍ£©£¬ÐòÁÐÔªËØÊÇÔÐòÁÐÖÐÓÉÖ¸¶¨µÄº¯Êýɸѡ³öÀ´µÄÄÇЩ£¬É¸Ñ¡¹æÔòÊÇ“º¯Êý(ÐòÁÐÔªËØ)=true”¡£filter()¿ÉÒÔ
ÓÃÀ´È¡³öÂú×ãÌõ¼þµÄ×Ó¼¯
map()
map(º¯Êý£¬ÐòÁÐ) - ¶ÔÖ¸¶¨ÐòÁеÄÿһÏîµ÷ÓÃÖ¸¶¨µÄº¯Êý£¬½á¹ûΪ·µ»ØÖµ×é³ÉµÄÁÐ±í¡£map() ¿ÉÒÔ¶ÔÐòÁнøÐÐÒþʽѻ·
reduce()
reduce(º¯Êý, ÐòÁÐ) -
ÓÃÀ´½øÐÐÀàËÆÀÛ¼ÓÕâÑùµÄ²Ù×÷£¬ÕâÀïµÄº¯ÊýÊÇÒ»¸öÁ½¸ö×Ó±äÁ¿µÄº¯Êý£¬reduce()ÏȶÔÐòÁеÄÇ°Á½Ïîµ÷Óú¯ÊýµÃµ½Ò»¸ö
Ïà¹ØÎĵµ£º
Python Áбí
listÊÇ´¦ÀíÒ»×éÓÐÐòÏîÄ¿µÄÊý¾Ý½á¹¹£¬¼´Äã¿ÉÒÔÔÚÒ»¸öÁбíÖд洢һ¸ö ÐòÁÐ µÄÏîÄ¿¡£¼ÙÏëÄãÓÐÒ»¸ö¹ºÎïÁÐ±í£¬ÉÏÃæ¼ÇÔØ×ÅÄãÒªÂòµÄ¶«Î÷£¬Äã¾ÍÈÝÒ×Àí½âÁбíÁË¡£Ö»²»¹ýÔÚÄãµÄ¹ºÎï±íÉÏ£¬¿ÉÄÜÿÑù¶«Î÷¶¼¶À×ÔÕ¼ÓÐÒ»ÐУ¬¶øÔÚPythonÖУ¬ÄãÔÚÿ¸öÏîÄ¿Ö®¼äÓöººÅ·Ö¸î¡£
ÁбíÖеÄÏîÄ¿Ó¦¸Ã°üÀ¨ÔÚ·½À¨ºÅÖУ¬ÕâÑùPython¾ÍÖªµÀÄãÊ ......
Python ÐòÁÐ
ÁÐ±í¡¢Ôª×éºÍ×Ö·û´®¶¼ÊÇÐòÁУ¬µ«ÊÇÐòÁÐÊÇʲô£¬ËüÃÇΪʲôÈç´ËÌرðÄØ£¿ÐòÁеÄÁ½¸öÖ÷ÒªÌصãÊÇË÷Òý²Ù×÷·ûºÍÇÐƬ²Ù×÷·û¡£Ë÷Òý²Ù×÷·ûÈÃÎÒÃÇ¿ÉÒÔ´ÓÐòÁÐÖÐץȡһ¸öÌض¨ÏîÄ¿¡£ÇÐƬ²Ù×÷·ûÈÃÎÒÃÇÄܹ»»ñÈ¡ÐòÁеÄÒ»¸öÇÐƬ£¬¼´Ò»²¿·ÖÐòÁС£
ʹÓÃÐòÁÐ
Àý9.5 ʹÓÃÐòÁÐ
#!/usr/bin/python
# Filename: seq.py
shoplist ......
²»¶à˵ÁË£¬Ö±½Ó¿´´úÂë°É£¡
import os
path = 'e:/Download/'
kzm = []
kzmTemp = set()
kzmTemp2 = []
dict = {}
for root,dirs,files in os.walk(path):
for file in files:
ext = os.path.splitext(file)[1][1:]
  ......
µÚÒ»²½£º´î½¨ÊÖ»úÔËÐÐƽ̨
ÒªÔÚS60ÊÖ»úÉÏÔËÐÐPY¿ª·¢µÄÈí¼þ,Ê×ÏȾÍÒª´î½¨ÊÖ»úPYÔËÐл·¾³.ŵ»ùÑÇÊÖ»ú±¾Éí²»Ö§³ÖPython,ËùÒÔÒª°²×°Python²å¼þ.
PS£ºÒ»¶¨Òª°²×°ÔÚCÅÌ£¡ÎÒÒ»¿ªÊ¼×°E£¬½á¹û³öÏÖÁ˺ÜÑÏÖصÄÎÊÌ⣡²»¹ý,×î½üÍøÉÏ·¢ÏÖÓÐEÅÌ°æµÄÀ²,Äã¿ÉÒÔ×Ô¼ºÊÔÑéһϣ¬¹þ¹þ
PythonScriptShell_1_4_5_3rdEd.SIS
Pyth ......
¶Ô Python º¯ÊýµÄ"µ÷ÖÆ"£¬ÊÇÖ¸¶ÔÆä×ö³öºÏºõÐèÇóµÄÉèÖ᣾ßÌåµÄµ÷ÖÆ·½·¨£¬Êǽ«Æä²ÎÊýÉèΪ¹Ì¶¨Öµ£¨³£Êý£©¡£
É趨µ¥Ò»µÄ²ÎÊýÖµ
ÔÏȵĺ¯ÊýÊÇÕâÑùµÄ£º
>>> def foo(cooked, standard):
... print "foo called with cooked: %s, standard: %s" % \
... (cooked, standard)
µ÷ÓÃËü£º
>>> foo('a', ......