Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Python Áбí(list)²Ù×÷

´´½¨Áбí
sample_list = ['a',1,('a','b')]
Python Áбí²Ù×÷
sample_list = ['a','b',0,1,3]
µÃµ½ÁбíÖеÄijһ¸öÖµ
value_start = sample_list[0]
end_value =
sample_list[-1]
ɾ³ýÁбíµÄµÚÒ»¸öÖµ
del sample_list[0]
ÔÚÁбíÖвåÈëÒ»¸öÖµ
sample_list[0:0] = ['sample value']
µÃµ½ÁбíµÄ³¤¶È
list_length = len(sample_list)
Áбí±éÀú
for element in sample_list:
    print(element)
   
Python
Áбí¸ß¼¶²Ù×÷/¼¼ÇÉ
²úÉúÒ»¸öÊýÖµµÝÔöÁбí
num_inc_list = range(30)
#will return a list
[0,1,2,...,29]
ÓÃij¸ö¹Ì¶¨Öµ³õʼ»¯Áбí
initial_value = 0
list_length = 5
sample_list = [
initial_value for i in range(10)]
sample_list =
[initial_value]*list_length
# sample_list ==[0,0,0,0,0]
¸½£ºpythonÄÚÖÃÀàÐÍ
1¡¢list£ºÁÐ±í£¨¼´¶¯Ì¬Êý×飬C++±ê×¼¿âµÄvector£¬µ«¿Éº¬²»Í¬ÀàÐ͵ÄÔªËØÓÚÒ»¸ölistÖУ©
a
= ["I","you","he","she"]      ££ÔªËØ¿ÉΪÈκÎÀàÐÍ¡£
ϱ꣺°´Ï±ê¶Áд£¬¾Íµ±×÷Êý×é´¦Àí
ÒÔ0¿ªÊ¼£¬ÓиºÏ±êµÄʹÓÃ
0µÚÒ»¸öÔªËØ£¬-1×îºóÒ»¸öÔªËØ£¬
-lenµÚÒ»¸öÔª
ËØ£¬len-1×îºóÒ»¸öÔªËØ
È¡listµÄÔªËØÊýÁ¿               
len(list)  
#listµÄ³¤¶È¡£Êµ¼Ê¸Ã·½·¨Êǵ÷ÓÃÁ˴˶ÔÏóµÄ__len__(self)·½·¨¡£ 
´´½¨Á¬ÐøµÄlist
L = range(1,5)      #¼´ L=[1,2,3,4],²»º¬×îºóÒ»¸öÔªËØ
L =
range(1, 10, 2) #¼´ L=[1, 3, 5, 7, 9]
listµÄ·½·¨
L.append(var)   #×·¼ÓÔªËØ
L.insert(index,var)
L.pop(var)     
#·µ»Ø×îºóÒ»¸öÔªËØ£¬²¢´ÓlistÖÐɾ³ýÖ®
L.remove(var)   #ɾ³ýµÚÒ»´Î³öÏֵĸÃÔªËØ
L.count(var)   
#¸ÃÔªËØÔÚÁбíÖгöÏֵĸöÊý
L.index(var)    #¸ÃÔªËØµÄλÖÃ,ÎÞÔòÅ×Òì³£
L.extend(list) 
#×·¼Ólist£¬¼´ºÏ²¢listµ½LÉÏ
L.sort()        #ÅÅÐò
L.reverse()     #µ¹Ðò
list
²Ù×÷·û:,+,*£¬¹Ø¼ü×Ödel
a[1:]       #Ƭ¶Î²Ù×÷·û£¬ÓÃÓÚ×ÓlistµÄÌáÈ¡
[1,2]+[3,4]
#Ϊ[1,2,


Ïà¹ØÎĵµ£º

python ÕýÔò±í´ïʽºÍreÄ£¿é

ÕýÔò±í´ïʽÊÇËÑË÷¡¢Ìæ»»ºÍ½âÎö¸´ÔÓ×Ö·ûģʽµÄÒ»ÖÖÇ¿´ó¶ø±ê×¼µÄ·½·¨.
ÕýÔò±í´ïʽ£¨»ò RE£©ÊÇÒ»ÖÖСÐ͵ġ¢¸ß¶Èרҵ»¯µÄ±à³ÌÓïÑÔ£¬£¨ÔÚPythonÖУ©ËüÄÚǶÔÚPythonÖУ¬²¢Í¨¹ý re Ä£¿éʵÏÖ.×Ö·û´®Ò²Óкܶ෽·¨,¿ÉÒÔ½øÐÐËÑË÷ (index¡¢find ºÍ count)¡¢Ìæ»» (replace) ºÍ½â
Îö (split),µ«ËüÃǽöÏÞÓÚ´¦Àí×î¼òµ¥µÄÇé¿ö
re Ä£¿éʹ P ......

Python modules : os, subprocess and commands

1. What’s the difference between all of the os.popen() methods?
popen2 doesn't capture standard error, popen3 does capture standard
error and gives a unique file handle for it. Finally, popen4 captures
standard error but includes it in the same file object as standard
output.
os.popen()&n ......

Python ÐòÁÐ


Python ÐòÁÐ
ÁÐ±í¡¢Ôª×éºÍ×Ö·û´®¶¼ÊÇÐòÁУ¬µ«ÊÇÐòÁÐÊÇʲô£¬ËüÃÇΪʲôÈç´ËÌØ±ðÄØ£¿ÐòÁеÄÁ½¸öÖ÷ÒªÌØµãÊÇË÷Òý²Ù×÷·ûºÍÇÐÆ¬²Ù×÷·û¡£Ë÷Òý²Ù×÷·ûÈÃÎÒÃÇ¿ÉÒÔ´ÓÐòÁÐÖÐץȡһ¸öÌØ¶¨ÏîÄ¿¡£ÇÐÆ¬²Ù×÷·ûÈÃÎÒÃÇÄܹ»»ñÈ¡ÐòÁеÄÒ»¸öÇÐÆ¬£¬¼´Ò»²¿·ÖÐòÁС£
ʹÓÃÐòÁÐ
Àý9.5 ʹÓÃÐòÁÐ
#!/usr/bin/python
# Filename: seq.py
shoplist ......

Amusing Python 2: range/xrange

ÕâÁ½¸ö»ù±¾É϶¼ÊÇÔÚÑ­»·µÄʱºòÓá£
Python
´úÂë < type="application/x-shockwave-flash" width="14" height="15" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=for%20i% ......

python ÅÀ³æ³ÌÐòÏê½â

1 #!/usr/bin/python ʹÓÃħ·¨×Ö·ûµ÷ÓÃpython
2
3 from sys import argv  µ¼ÈësysÊǵ¼Èëpython½âÊÍÆ÷ºÍËû»·¾³Ïà¹ØµÄ²ÎÊý
4 from os import makedirs,unlink,sep
osÖ÷ÒªÌṩ¶Ôϵͳ·¾¶£¬ÎļþÖØÃüÃûºÍɾ³ýÎļþËùÐèµÄº¯Êý
makedirsÊÇ´´½¨µÝ¹éÎļþ¼ÐµÄº¯Êý¡£±ÈÈç˵ÎÒÃÇÒª´´½¨Ò»¸öеÄĿ¼£¬/python/HTML/crawl,µ«ÊÇÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ