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

Python Áбí

Python Áбí
listÊÇ´¦ÀíÒ»×éÓÐÐòÏîÄ¿µÄÊý¾Ý½á¹¹£¬¼´Äã¿ÉÒÔÔÚÒ»¸öÁбíÖд洢һ¸ö ÐòÁÐ µÄÏîÄ¿¡£¼ÙÏëÄãÓÐÒ»¸ö¹ºÎïÁÐ±í£¬ÉÏÃæ¼ÇÔØ×ÅÄãÒªÂòµÄ¶«Î÷£¬Äã¾ÍÈÝÒ×Àí½âÁбíÁË¡£Ö»²»¹ýÔÚÄãµÄ¹ºÎï±íÉÏ£¬¿ÉÄÜÿÑù¶«Î÷¶¼¶À×ÔÕ¼ÓÐÒ»ÐУ¬¶øÔÚPythonÖУ¬ÄãÔÚÿ¸öÏîÄ¿Ö®¼äÓöººÅ·Ö¸î¡£
ÁбíÖеÄÏîÄ¿Ó¦¸Ã°üÀ¨ÔÚ·½À¨ºÅÖУ¬ÕâÑùPython¾ÍÖªµÀÄãÊÇÔÚÖ¸Ã÷Ò»¸öÁÐ±í¡£Ò»µ©Äã´´½¨ÁËÒ»¸öÁÐ±í£¬Äã¿ÉÒÔÌí¼Ó¡¢É¾³ý»òÊÇËÑË÷ÁбíÖеÄÏîÄ¿¡£ÓÉÓÚÄã¿ÉÒÔÔö¼Ó»òɾ³ýÏîÄ¿£¬ÎÒÃÇ˵ÁбíÊÇ ¿É±äµÄ Êý¾ÝÀàÐÍ£¬¼´ÕâÖÖÀàÐÍÊÇ¿ÉÒÔ±»¸Ä±äµÄ¡£
¶ÔÏóÓëÀàµÄ¿ìËÙÈëÃÅ
¾¡¹ÜÎÒÒ»Ö±ÍƳÙÌÖÂÛ¶ÔÏóºÍÀ࣬µ«ÊÇÏÖÔÚ¶ÔËüÃÇ×öÒ»µã½âÊÍ¿ÉÒÔʹÄã¸üºÃµÄÀí½âÁÐ±í¡£ÎÒÃÇ»áÔÚÏàÓ¦µÄÕ½ÚÏêϸ̽Ë÷Õâ¸öÖ÷Ìâ¡£
ÁбíÊÇʹÓöÔÏóºÍÀàµÄÒ»¸öÀý×Ó¡£µ±ÄãʹÓñäÁ¿i²¢¸øËü¸³ÖµµÄʱºò£¬±ÈÈ縳ÕûÊý5£¬Äã¿ÉÒÔÈÏΪÄã´´½¨ÁËÒ»¸öÀࣨÀàÐÍ£©intµÄ¶ÔÏó£¨ÊµÀý£©i¡£ÊÂʵÉÏ£¬Äã¿ÉÒÔ¿´Ò»ÏÂhelp(int)ÒÔ¸üºÃµØÀí½âÕâÒ»µã¡£
ÀàÒ²Óз½·¨£¬¼´½ö½öΪÀà¶ø¶¨ÒåµØº¯Êý¡£½ö½öÔÚÄãÓÐÒ»¸ö¸ÃÀàµÄ¶ÔÏóµÄʱºò£¬Äã²Å¿ÉÒÔʹÓÃÕâЩ¹¦ÄÜ¡£ÀýÈ磬PythonΪlistÀàÌṩÁËappend·½·¨£¬Õâ¸ö·½·¨ÈÃÄãÔÚÁбíβÌí¼ÓÒ»¸öÏîÄ¿¡£ÀýÈçmylist.append('an item')ÁбímylistÖÐÔö¼ÓÄǸö×Ö·û´®¡£×¢Ò⣬ʹÓõãºÅÀ´Ê¹ÓöÔÏóµÄ·½·¨¡£
Ò»¸öÀàÒ²ÓÐÓò£¬ËüÊǽö½öΪÀà¶ø¶¨ÒåµÄ±äÁ¿¡£½ö½öÔÚÄãÓÐÒ»¸ö¸ÃÀàµÄ¶ÔÏóµÄʱºò£¬Äã²Å¿ÉÒÔʹÓÃÕâЩ±äÁ¿/Ãû³Æ¡£ÀàҲͨ¹ýµãºÅʹÓã¬ÀýÈçmylist.field¡£
ʹÓÃÁбí
Àý9.1 ʹÓÃÁбí
#!/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
£¨Ô´Îļþ£ºcode/using_list.py£©
Êä³ö
$ python using_list.py
I have 4 items to purchase.
These items are: apple mango carrot banana
I also have to buy


Ïà¹ØÎĵµ£º

ÉæË®The Python Challenge

ÔÚStack Overflow ÉÏ¿´µ½Ñ§Ï°Python µÄÒ»¸ö·½·¨ÊÇÓÃPython ÆƽâThe Python Challenge¡£µ«ÎÒϲ»¶ÓÃRuby£¬Ë­¹ÜµÃ×ÅÄØ^_^
0. ÈëÃŹغܼòµ¥¡£
p 2**38 
1. ÆƽâÒ»¶Î»°£¬¹Û²ìͼƬºÜÈÝÒ×·¢ÏÖ½âÂë±í°Ñ×Öĸ±íÑ­»·ÓÒÒÆÁ½Î»¡£
riddle = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl ......

PythonÖеĵ¥Ôª²âÊÔ

   ½ñÍíÊÔÁËÒ»ÏÂPython×Ô´øµÄµ¥Ôª²âÊÔ£¬Ö÷ÒªÊDzο¼ÁËPythonµ¥Ôª²âÊÔ¿ò¼Ü
µÄÓйØ×ÊÁÏ£¬ÕÛÌÚÁËÒ»¸öСʱ×óÓÒ£¬×ÜËãÔÚEric 4ͨ¹ýµÄ¼¸¸ö¼òµ¥µÄµ¥Ôª²âÊÔ¡£ÔÚÕâÀォËùµÃµÄÏà¹Ø֪ʶ¼Ç¼ÏÂÀ´£¬·½±ã½«À´²éѯ¡£
    python×Ô´øµÄµ¥Ôª²âÊÔÄ£¿éÊÇunittest£¬´Ó2.1ÒÔºóΪ±ê×¼¿âµÄÒ»²¿·Ö
    1 ......

python ÖÐ base64 ѹËõͼƬ£¬ÓÃpost´«ËÍ


Including binaries in your sources
+y F J2A T&N1H f(L ]0
Sometime it's handy to include small files in your sources (icons, test files, etc.)CNOUG²©¿ÍÊ×Ò³ P x z c W R K+x3{ N
CNOUG²©¿ÍÊ×Ò³ h I A O$k-n P
Let's take a file (myimage.gif) and convert it in base64 (optionnaly compressing it wit ......

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

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

pythonÄ£¿é

¼ò½é
ÄãÒѾ­Ñ§Ï°ÁËÈçºÎÔÚÄãµÄ³ÌÐòÖж¨ÒåÒ»´Îº¯Êý¶øÖØÓôúÂë¡£Èç¹ûÄãÏëÒªÔÚÆäËû³ÌÐòÖÐÖØÓúܶຯÊý£¬ÄÇôÄã¸ÃÈçºÎ±àд³ÌÐòÄØ£¿Äã¿ÉÄÜÒѾ­²Âµ½ÁË£¬´ð°¸ÊÇʹÓÃÄ£¿é¡£Ä£¿é»ù±¾ÉϾÍÊÇÒ»¸ö°üº¬ÁËËùÓÐÄ㶨ÒåµÄº¯ÊýºÍ±äÁ¿µÄÎļþ¡£ÎªÁËÔÚÆäËû³ÌÐòÖÐÖØÓÃÄ£¿é£¬Ä£¿éµÄÎļþÃû±ØÐëÒÔ.pyΪÀ©Õ¹Ãû¡£
Ä£¿é¿ÉÒÔ´ÓÆäËû³ÌÐò ÊäÈë ÒÔ±ãÀûÓÃËüµ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ