pythonÁбíºÍ×ÖµäµÄ·½·¨×ܽá
ÁÐ±í·½·¨£º
·½·¨
˵Ã÷
append( item )
ÔÚÁбíĩβ²åÈ루item £©
count( element )
·µ»ØelementÔÚÁбíÖгöÏֵĴÎÊý
extend( newlist )
½«newlistµÄÔªËزåÈëÁбíĩβ
index( element )
·µ»ØelementÔÚÁбíÖеÄË÷Òý£¬Èç¹û²»´æÔÚ£¬ÔòÒý·¢ValueErrorÒì³£
insert( index , item )
ÔÚindexλÖòåÈëitem
pop( [index] )
index²ÎÊýΪ¿ÉÑ¡µÄ¡£ÈçÎ޲ε÷Óã¬Ôò»áɾ³ý²¢·µ»ØÁбí×îºóÒ»¸öÔªËØ¡£ÈçÖ¸¶¨index²Î
Êý£¬Ôòɾ³ý²¢·µ»ØλÖÃindexµÄÔªËØ
remove( element )
ɾ³ýÊ×´ÎÔÚÁбíÖгöÏÖµÄelement£¬Èç¹ûÁÐ±í²»´æÔÚelement£¬ÔòÒý·¢
ValueErrorÒì³£
reverse( )
µ±³¡·´×ªÁбíÄÚÈÝ£¨²»´´½¨·´×ªÁбíµÄ¿½±´£©
sort
µ±³¡¶ÔÁбíÄÚÈÝÅÅÐò¡£¿ÉÑ¡²ÎÊýcompare-functionÊÇÒ»¸öº¯Êý£¬ËüÖ¸¶¨Á˱ȽÏÌõ¼þ
compare-functionÈ¡µÃÁбíµÄÈÎÒâÁ½¸öÔªËØ£¨xºÍy£©¡£Èç¹ûxÓ¦³öÏÖÔÚy֮ǰ£¬
¾Í·¶Î§-1£»Èç¹ûxºÍyµÄ˳ÐòÎ޹ؽôÒª£¬·µ»Ø0£»Èç¹ûxÓ¦³öÏÖÔÚyÖ®ºó£¬Ôò·µ»Ø1
×ÖµäµÄһЩ·½·¨£º
·½·¨
˵Ã÷
clear( )
´Ó×Öµäɾ³ýËùÓÐÏî
copy( )
´´½¨²¢·µ»Ø×ÖµäµÄdz¿½±´£¨ÐÂ×ÖµäÔªËØΪÔʼ×ÖµäµÄÒýÓã©
get(key [ ,returnvalue] )
·µ»ØkeyµÄÖµ£¬ÈôÎÞkey¶øÖ¸¶¨ÁËreturnvalue£¬Ôò·µ»Øreturnvalue
Öµ£¬ÈôÎÞ´ËÖµÔò·µ»ØNone
has_key( key )
Èç¹ûkey´æÔÚÓÚ×ÖµäÖУ¬¾Í·µ»Ø1£¨Õ棩£»·ñÔò·µ»Ø0£¨¼Ù£©
items( )
·µ»ØÒ»¸öÓÉÔª×é¹¹³ÉµÄÁÐ±í£¬Ã¿¸öÔª×é°üº¬Ò»¶Ô¼ü-Öµ¶Ô
keys( )
·µ»ØÒ»¸öÓÉ×ÖµäËùÓмü¹¹³ÉµÄÁбí
popitem( )
ɾ³ýÈÎÒâ¼ü-Öµ¶Ô£¬²¢×÷ΪÁ½¸öÔªËصÄÔª×é·µ»Ø¡£Èç×ÖµäΪ¿Õ£¬Ôò·µ»ØKeyErrorÒì³£
setdefault( key [,dummvalue])
¾ßÓÐÓëget·½·¨ÀàËƵÄÐÐΪ¡£Èçkey²»ÔÚ×ÖµäÖУ¬Í¬Ê±Ö¸¶¨ÁËdummvalue£¬¾Í½«¼ü
£¨key£©ºÍÖ¸¶¨µÄÖµ£¨dummvalue£©²åÈë×ֵ䣬Èç¹ûûÓÐÖ¸¶¨dummvalue£¬ÔòֵΪNone
update( newDictionary )
½«À´×ÔnewDictionaryµÄËùÓмü-ÖµÌí¼Óµ½µ±Ç°×ֵ䣬²¢¸²¸ÇͬÃû¼üµÄÖµ
values( )
·µ»Ø×ÖµäËùÓÐÖµ×é³ÉµÄÒ»¸öÁбí
iterkeys( )
·µ»Ø×Öµä¼üµÄÒ»¸öµü´úÆ÷
iteritems( )
·µ»Ø×Öµä¼ü-Öµ¶ÔµÄÒ»¸öµü´úÆ÷
itervalues( )
·µ»Ø×ÖµäÖµµÄÒ»¸öµü´úÆ÷
Ïà¹ØÎĵµ£º
Python ×Öµä
×ÖµäÀàËÆÓÚÄãͨ¹ýÁªÏµÈËÃû×Ö²éÕÒµØÖ·ºÍÁªÏµÈËÏêϸÇé¿öµÄµØÖ·²¾£¬¼´£¬ÎÒÃǰѼü£¨Ãû×Ö£©ºÍÖµ£¨ÏêϸÇé¿ö£©ÁªÏµÔÚÒ»Æð¡£×¢Ò⣬¼ü±ØÐëÊÇΨһµÄ£¬¾ÍÏñÈç¹ûÓÐÁ½¸öÈËÇ¡ÇÉͬÃûµÄ»°£¬ÄãÎÞ·¨ÕÒµ½ÕýÈ·µÄÐÅÏ¢¡£
×¢Ò⣬ÄãÖ»ÄÜʹÓò»¿É±äµÄ¶ÔÏ󣨱ÈÈç×Ö·û´®£©À´×÷Ϊ×ÖµäµÄ¼ü£¬µ«ÊÇÄã¿ÉÒÔ²»¿É±ä»ò¿É±äµÄ¶ÔÏó×÷Ϊ×Öµäµ ......
Python ÐòÁÐ
ÁÐ±í¡¢Ôª×éºÍ×Ö·û´®¶¼ÊÇÐòÁУ¬µ«ÊÇÐòÁÐÊÇʲô£¬ËüÃÇΪʲôÈç´ËÌرðÄØ£¿ÐòÁеÄÁ½¸öÖ÷ÒªÌصãÊÇË÷Òý²Ù×÷·ûºÍÇÐƬ²Ù×÷·û¡£Ë÷Òý²Ù×÷·ûÈÃÎÒÃÇ¿ÉÒÔ´ÓÐòÁÐÖÐץȡһ¸öÌض¨ÏîÄ¿¡£ÇÐƬ²Ù×÷·ûÈÃÎÒÃÇÄܹ»»ñÈ¡ÐòÁеÄÒ»¸öÇÐƬ£¬¼´Ò»²¿·ÖÐòÁС£
ʹÓÃÐòÁÐ
Àý9.5 ʹÓÃÐòÁÐ
#!/usr/bin/python
# Filename: seq.py
shoplist ......
±ê׼ͷ²¿
#!/usr/bin/python
±àÂë
ËùÓÐµÄ Python ½Å±¾Îļþ¶¼Ó¦ÔÚÎļþÍ·±êÉÏ #-*- coding:utf8 -*- ¡£ÉèÖñà¼Æ÷£¬Ä¬Èϱ£´æΪ utf8 ¸ñʽ¡£
mainº¯Êý
Ó¦ÓóÌÐòÒª¶¨Òåmainº¯Êý¶ø²»ÒªÖ±½Óд½Å±¾
def main():
dosomething()
if
__name__ == "__main__"
:
main()
Èç¹ûÊÇÈ«¾Ö±äÁ¿£¬ÔòÐèÒªÏÔʽ¼ÓÉ ......
python ûÓÐÊý×éµÄÊý¾Ý½á¹¹
#list ÐòÁÐ
sample_list = [1,2,3,'abc']
#dictionary ×Öµä
sample_dic = {"key":value, 2:3}
#tuple Ö»¶ÁµÄÐòÁÐ
sample_tuple = (1,3,"ab")
Ðò±í
Ðò±íÓÉһϵÁÐÖµÓöººÅ·Ö¸ô¶ø³É
Ðò±íÓë×Ö·û´®Ò»ÑùÊDz»¿É±äµÄ£º²»ÔÊÐí¶ÔÐ ......