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

Python ÐòÁÐ


Python ÐòÁÐ
ÁÐ±í¡¢Ôª×éºÍ×Ö·û´®¶¼ÊÇÐòÁУ¬µ«ÊÇÐòÁÐÊÇʲô£¬ËüÃÇΪʲôÈç´ËÌØ±ðÄØ£¿ÐòÁеÄÁ½¸öÖ÷ÒªÌØµãÊÇË÷Òý²Ù×÷·ûºÍÇÐÆ¬²Ù×÷·û¡£Ë÷Òý²Ù×÷·ûÈÃÎÒÃÇ¿ÉÒÔ´ÓÐòÁÐÖÐץȡһ¸öÌØ¶¨ÏîÄ¿¡£ÇÐÆ¬²Ù×÷·ûÈÃÎÒÃÇÄܹ»»ñÈ¡ÐòÁеÄÒ»¸öÇÐÆ¬£¬¼´Ò»²¿·ÖÐòÁС£
ʹÓÃÐòÁÐ
Àý9.5 ʹÓÃÐòÁÐ
#!/usr/bin/python
# Filename: seq.py
shoplist = ['apple', 'mango', 'carrot', 'banana']
# Indexing or 'Subscription' operation
print 'Item 0 is', shoplist[0]
print 'Item 1 is', shoplist[1]
print 'Item 2 is', shoplist[2]
print 'Item 3 is', shoplist[3]
print 'Item -1 is', shoplist[-1]
print 'Item -2 is', shoplist[-2]
# Slicing on a list
print 'Item 1 to 3 is', shoplist[1:3]
print 'Item 2 to end is', shoplist[2:]
print 'Item 1 to -1 is', shoplist[1:-1]
print 'Item start to end is', shoplist[:]
# Slicing on a string
name = 'swaroop'
print 'characters 1 to 3 is', name[1:3]
print 'characters 2 to end is', name[2:]
print 'characters 1 to -1 is', name[1:-1]
print 'characters start to end is', name[:]
£¨Ô´Îļþ£ºcode/seq.py£©
Êä³ö
$ python seq.py
Item 0 is apple
Item 1 is mango
Item 2 is carrot
Item 3 is banana
Item -1 is banana
Item -2 is carrot
Item 1 to 3 is ['mango', 'carrot']
Item 2 to end is ['carrot', 'banana']
Item 1 to -1 is ['mango', 'carrot']
Item start to end is ['apple', 'mango', 'carrot', 'banana']
characters 1 to 3 is wa
characters 2 to end is aroop
characters 1 to -1 is waroo
characters start to end is swaroop
ËüÈçºÎ¹¤×÷
Ê×ÏÈ£¬ÎÒÃÇÀ´Ñ§Ï°ÈçºÎʹÓÃË÷ÒýÀ´È¡µÃÐòÁÐÖеĵ¥¸öÏîÄ¿¡£ÕâÒ²±»³Æ×÷ÊÇϱê²Ù×÷¡£Ã¿µ±ÄãÓ÷½À¨ºÅÖеÄÒ»¸öÊýÀ´Ö¸¶¨Ò»¸öÐòÁеÄʱºò£¬Python»áΪÄãץȡÐòÁÐÖжÔӦλÖõÄÏîÄ¿¡£¼Çס£¬Python´Ó0¿ªÊ¼¼ÆÊý¡£Òò´Ë£¬shoplist[0]ץȡµÚÒ»¸öÏîÄ¿£¬shoplist[3]ץȡshoplistÐòÁÐÖеĵÚËĸöÔªËØ¡£
Ë÷ÒýͬÑù¿ÉÒÔÊǸºÊý£¬ÔÚÄÇÑùµÄÇé¿öÏ£¬Î»ÖÃÊÇ´ÓÐòÁÐβ¿ªÊ¼¼ÆËãµÄ¡£Òò´Ë£¬shoplist[-1]±íʾÐòÁеÄ×îºóÒ»¸öÔªËØ¶øshoplist[-2]ץȡÐòÁеĵ¹ÊýµÚ¶þ¸öÏîÄ¿¡£
ÇÐÆ¬²Ù×÷·ûÊÇÐòÁÐÃûºó¸úÒ»¸ö·½À¨ºÅ£¬·½À¨ºÅÖÐÓÐÒ»¶Ô¿ÉÑ¡µÄÊý×Ö£¬²¢ÓÃðºÅ·Ö¸î¡£×¢ÒâÕâÓëÄãʹÓõÄË÷Òý²Ù×÷·ûÊ®·ÖÏàËÆ¡£¼ÇסÊýÊÇ¿ÉÑ¡µÄ£¬¶øÃ°ºÅÊDZØÐëµÄ¡£
ÇÐÆ¬²Ù×÷·ûÖеĵ


Ïà¹ØÎĵµ£º

ʹÓà Django ºÍ Python ¿ª·¢ Web Õ¾µã


 
 
Ian Maurer (ian@itmaurer.com), ×ÊÉî¹ËÎÊ, Brulant, Inc.
2006 Äê 7 ÔÂ 03 ÈÕ
±¾ÏµÁÐÎÄÕÂÒ»¹²ÓÐÁ½Æª£¬±¾ÎÄÊÇÆäÖеĵÚһƪ¡£ÔÚÕâһƪÎÄÕÂÖУ¬ÎÒÃǽ«Õ¹Ê¾ Django µÄÓ÷¨£¬Django ÊÇ Python ±à³ÌÓïÑÔÇý¶¯µÄÒ»¸ö¿ªÔ´Ä£ÐÍ-ÊÓͼ-¿ØÖÆÆ÷£¨MVC£©·ç¸ñµÄ Web Ó¦ÓóÌÐò¿ò¼Ü¡£Ê¹Óà Django£¬ÎÒÃÇÔÚ¼¸·ÖÖÓÖ®ÄÚ¾ ......

Python±ê×¼¿â tracebackÄ£¿é

Example 2-18 չʾÁË traceback Ä£¿éÔÊÐíÄãÔÚ³ÌÐòÀï´òÓ¡Òì³£µÄ¸ú×Ù·µ»Ø
(Traceback)ÐÅÏ¢, ÀàËÆÎ´²¶»ñÒ쳣ʱ½âÊÍÆ÷Ëù×öµÄ. Èç Example 2-18 Ëùʾ. 2.11.0.1. Example
2-18. ʹÓà traceback Ä£¿é´òÓ¡¸ú×Ù·µ»ØÐÅÏ¢ File: traceback-example-1.py # note!
import
Example 2-18 չʾÁË traceback Ä£¿éÔÊÐíÄãÔÚ³ÌÐòÀï´òÓ¡Òì³£ ......

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 Áбí

Python Áбí
listÊÇ´¦ÀíÒ»×éÓÐÐòÏîÄ¿µÄÊý¾Ý½á¹¹£¬¼´Äã¿ÉÒÔÔÚÒ»¸öÁбíÖд洢һ¸ö ÐòÁÐ µÄÏîÄ¿¡£¼ÙÏëÄãÓÐÒ»¸ö¹ºÎïÁÐ±í£¬ÉÏÃæ¼ÇÔØ×ÅÄãÒªÂòµÄ¶«Î÷£¬Äã¾ÍÈÝÒ×Àí½âÁбíÁË¡£Ö»²»¹ýÔÚÄãµÄ¹ºÎï±íÉÏ£¬¿ÉÄÜÿÑù¶«Î÷¶¼¶À×ÔÕ¼ÓÐÒ»ÐУ¬¶øÔÚPythonÖУ¬ÄãÔÚÿ¸öÏîĿ֮¼äÓöººÅ·Ö¸î¡£
ÁбíÖеÄÏîĿӦ¸Ã°üÀ¨ÔÚ·½À¨ºÅÖУ¬ÕâÑùPython¾ÍÖªµÀÄãÊ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ