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
Ïà¹ØÎĵµ£º
ÔÚ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×Ô´øµÄµ¥Ôª²âÊÔ£¬Ö÷ÒªÊDzο¼ÁËPythonµ¥Ôª²âÊÔ¿ò¼Ü
µÄÓйØ×ÊÁÏ£¬ÕÛÌÚÁËÒ»¸öСʱ×óÓÒ£¬×ÜËãÔÚEric 4ͨ¹ýµÄ¼¸¸ö¼òµ¥µÄµ¥Ôª²âÊÔ¡£ÔÚÕâÀォËùµÃµÄÏà¹Ø֪ʶ¼Ç¼ÏÂÀ´£¬·½±ã½«À´²éѯ¡£
python×Ô´øµÄµ¥Ôª²âÊÔÄ£¿éÊÇunittest£¬´Ó2.1ÒÔºóΪ±ê×¼¿âµÄÒ»²¿·Ö
1 ......
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 ......
ÕýÔò±í´ïʽÊÇËÑË÷¡¢Ìæ»»ºÍ½âÎö¸´ÔÓ×Ö·ûģʽµÄÒ»ÖÖÇ¿´ó¶ø±ê×¼µÄ·½·¨.
ÕýÔò±í´ïʽ£¨»ò RE£©ÊÇÒ»ÖÖСÐ͵ġ¢¸ß¶Èרҵ»¯µÄ±à³ÌÓïÑÔ£¬£¨ÔÚPythonÖУ©ËüÄÚǶÔÚPythonÖУ¬²¢Í¨¹ý re Ä£¿éʵÏÖ.×Ö·û´®Ò²Óкܶ෽·¨,¿ÉÒÔ½øÐÐËÑË÷ (index¡¢find ºÍ count)¡¢Ìæ»» (replace) ºÍ½â
Îö (split),µ«ËüÃǽöÏÞÓÚ´¦Àí×î¼òµ¥µÄÇé¿ö
re Ä£¿éʹ P ......
¼ò½é
ÄãÒѾѧϰÁËÈçºÎÔÚÄãµÄ³ÌÐòÖж¨ÒåÒ»´Îº¯Êý¶øÖØÓôúÂë¡£Èç¹ûÄãÏëÒªÔÚÆäËû³ÌÐòÖÐÖØÓúܶຯÊý£¬ÄÇôÄã¸ÃÈçºÎ±àд³ÌÐòÄØ£¿Äã¿ÉÄÜÒѾ²Âµ½ÁË£¬´ð°¸ÊÇʹÓÃÄ£¿é¡£Ä£¿é»ù±¾ÉϾÍÊÇÒ»¸ö°üº¬ÁËËùÓÐÄ㶨ÒåµÄº¯ÊýºÍ±äÁ¿µÄÎļþ¡£ÎªÁËÔÚÆäËû³ÌÐòÖÐÖØÓÃÄ£¿é£¬Ä£¿éµÄÎļþÃû±ØÐëÒÔ.pyΪÀ©Õ¹Ãû¡£
Ä£¿é¿ÉÒÔ´ÓÆäËû³ÌÐò ÊäÈë ÒÔ±ãÀûÓÃËüµ ......