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

Python±Ê¼Ç£¨6£©

 Êý¾Ý½á¹¹
 
Ò».¼ò½é
Êý¾Ý½á¹¹»ù±¾ÉϾÍÊÇ——ËüÃÇÊÇ¿ÉÒÔ´¦ÀíһЩÊý¾ÝµÄ½á¹¹¡£»òÕß˵£¬ËüÃÇÊÇÓÃÀ´´æ´¢Ò»×éÏà¹ØÊý¾ÝµÄ¡£
ÔÚPythonÖÐÓÐÈýÖÖÄÚ½¨µÄÊý¾Ý½á¹¹——ÁÐ±í¡¢Ôª×éºÍ×ֵ䡣ÎÒÃǽ«»áѧϰÈçºÎʹÓÃËüÃÇ£¬ÒÔ¼°ËüÃÇÈçºÎʹ±à³Ì±äµÃ¼òµ¥¡£
¶þ.Áбí
listÊÇ´¦ÀíÒ»×éÓÐÐòÏîÄ¿µÄÊý¾Ý½á¹¹£¬¼´Äã¿ÉÒÔÔÚÒ»¸öÁбíÖд洢һ¸öÐòÁеÄÏîÄ¿¡£
Ò»µ©Äã´´½¨ÁËÒ»¸öÁÐ±í£¬Äã¿ÉÒÔÌí¼Ó¡¢É¾³ý»òÊÇËÑË÷ÁбíÖеÄÏîÄ¿¡£ÓÉÓÚÄã¿ÉÒÔÔö¼Ó»òɾ³ýÏîÄ¿£¬ÎÒÃÇ˵ÁбíÊǿɱäµÄÊý¾ÝÀàÐÍ£¬¼´ÕâÖÖÀàÐÍÊÇ¿ÉÒÔ±»¸Ä±äµÄ¡£ÔÚijÖ̶ֳÈÉÏ£¬ÓëÊý×éÀàËÆ¡£
ÀýÈç:
#!/usr/bin/python
# Filename: using_list.py
# This is my shopping list
shoplist = ['apple', 'mango', 'carrot', 'banana']
print 'I have', len(shoplist),'items to purchase.'
print 'These items are:', # Notice the comma at end of the line
for item in shoplist:
print item,
print '\nI also have to buy rice.'
shoplist.append('rice')
print 'My shopping list is now', shoplist
print 'I will sort my list now'
shoplist.sort()
print 'Sorted shopping list is', shoplist
print 'The first item I will buy is', shoplist[0]
olditem = shoplist[0]
del shoplist[0]
print 'I bought the', olditem
print 'My shopping list is now', shoplist

Êä³öΪ:
$ python using_list.py
I have 4 items to purchase.
These items are: apple mango carrot banana
I also have to buy rice.
My shopping list is now ['apple', 'mango', 'carrot', 'banana', 'rice']
I will sort my list now
Sorted shopping list is ['apple', 'banana', 'carrot', 'mango', 'rice']
The first item I will buy is apple
I bought the apple
My shopping list is now ['banana', 'carrot', 'mango', 'rice']

Èý.Ôª×é
Ôª×éºÍÁбíÊ®·ÖÀàËÆ£¬Ö»²»¹ýÔª×éºÍ×Ö·û´®Ò»ÑùÊDz»¿É±äµÄ¼´Äã²»ÄÜÐÞ¸ÄÔª×é¡£Ôª×éͨ¹ýÔ²À¨ºÅÖÐÓöººÅ·Ö¸îµÄÏîÄ¿¶¨Òå¡£Ôª×éͨ³£ÓÃÔÚʹÓï¾ä»òÓû§¶¨ÒåµÄº¯ÊýÄܹ»°²È«µØ²ÉÓÃÒ»×éÖµµÄʱºò£¬¼´±»Ê¹ÓõÄÔª×éµÄÖµ²»»á¸Ä±ä¡£
ËÄ.×Öµä
×ÖµäÀàËÆÓÚÄãͨ¹ýÁªÏµÈËÃû×Ö²éÕÒµØÖ·ºÍÁªÏµÈËÏêϸÇé¿öµÄµØÖ·²¾£¬¼´£¬ÎÒÃǰѼü£¨Ãû×Ö£©ºÍÖµ£¨ÏêϸÇé¿ö£©ÁªÏµÔÚÒ»Æð¡£×¢Ò⣬¼ü±ØÐëÊÇΨһµÄ¡£
×¢Ò⣬ÄãÖ»ÄÜʹÓò»¿É±äµÄ¶ÔÏ󣨱ÈÈç×Ö·û´®£©À´×÷Ϊ×ÖµäµÄ¼ü£¬µ«ÊÇÄã¿


Ïà¹ØÎĵµ£º

python±Ê¼ÇÖ®ÕýÔò±í´ïʽ

 ÕýÔò±í´ïʽ
¾ßÌåµÄ²Î¿¼ÊֲᣬÕâÀï¼ÇÏÂһЩСÎÊÌ⣺
1¡¢re¶ÔÏóµÄ·½·¨
match    Match a regular expression pattern to the beginning of a string.
search   re.search(pattern, string, flags) flags:re.I re.M re.X re.S re.L re.U
sub      Substitute oc ......

(ת) pythonÓ¦ÓÃÁìÓò½éÉÜ

#---------------------תתתתתתתתתתתתתתתתתתתתתתת-------------------------------------------#
Python×÷ΪһÖÖ¹¦ÄÜÇ¿´óÇÒͨÓõıà³ÌÓïÑÔ¶ø¹ãÊÜºÃÆÀ£¬Ëü¾ßÓзdz£ÇåÎúµÄÓï·¨ÌØµã£¬ÊÊÓÃÓÚ¶àÖÖ²Ù×÷ϵͳ£¬Ä¿Ç°ÔÚ¹ú¼ÊÉϷdz£Á÷ÐУ¬ÕýÔڵõ½Ô½À´Ô½¶àµÄÓ¦Óá£
 
¡¡¡¡ÏÂÃæ¾ÍÈÃÎÒÃÇÒ»ÆðÀ´¿´¿´ËüµÄÇ¿´ó ......

Python ιʶøÖªÐÂ

1. ´òÓ¡±äÁ¿ºÍ±äÁ¿×ÔÏÔ
>>> myString = 'Hello World!'
>>> print myString
Hello World!
>>> myString
'Hello World!'
ÒòΪ£º print Óï¾äµ÷ÓÃstr()º¯ÊýÏÔʾ¶ÔÏ󣬶ø½»»¥Ê½½âÊÍÆ÷Ôòµ÷ÓÃrepr()º¯ÊýÀ´ÏÔʾ¶ÔÏó
sys.stdout.write('hello')²»»áÔÚĩβ¼ÓÉÏ'\n'£¬¶øprint»á
2. ´òÓ¡Îļþ
hand ......

Python Socket ±à³Ì

client:
import socket, sys
if __name__ == '__main__':
    #´¦Àí²ÎÊý
    argv = sys.argv
    if (len(argv)!=3) or (len(argv)==2 and argv[1]=='/?'):
        print '>>>Useage:', argv[0], '<address> < ......

Python±Ê¼Ç£¨5£©

Ä£¿é
 
Ò».¼ò½é
Ä£¿é»ù±¾ÉϾÍÊÇÒ»¸ö°üº¬ÁËËùÓÐÄ㶨ÒåµÄº¯ÊýºÍ±äÁ¿µÄÎļþ¡£ÎªÁËÔÚÆäËû³ÌÐòÖÐÖØÓÃÄ£¿é£¬Ä£¿éµÄÎļþÃû±ØÐëÒÔ.pyΪÀ©Õ¹Ãû¡£
 
ÀýÈ磺
 
#!/usr/bin/python
# Filename: using_sys.py
import sys
print 'The command line arguments are:'
for i in sys.argv:
print i
print '\n ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ