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ØÐëµÄ¡£
ÇÐÆ¬²Ù×÷·ûÖеĵ
Ïà¹ØÎĵµ£º
ÔÚ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 ......
ÒÔǰҲд¹ýһЩ¹ØÓÚ vim »·¾³±äÁ¿µÄÄÚÈÝ£¬Ê¹Óà vim ºÍ python £¬Ã¿Ò»¶Îʱ¼äºó¶¼»áÓÐеÄÌå»á£¬ËùÒÔÒª²»¶Ï×ܽáÁË.
vim Õë¶Ô python µÄÍòÄܲ¹È«£º vim µ±Ç°½ø³ÌÐèÒªÕÒµ½ÏàÓ¦²¹È«Ä£¿é¿âËùÔÚλÖ㬴ËÊÇ¾ÍºÍ python µÄpath»·¾³±äÁ¿Ïà¹Ø¡£
python ´úÂëÔËÐÐʱ: ¶ÔÓÚimport µÄÄ£¿éÒ²ÐèҪȷ¶¨ËüµÄ¾ßÌåλÖÃ,python ½âÊÍÆ÷»áµ½µ±Ç°Â· ......
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ÃüÁÐèÒª½«python.exeËùÔÚµÄĿ¼¸½¼Óµ½PATHÕâ¸ö»·¾³±äÁ¿ÖС£
¶þ¡¢ÈçºÎʹPython½âÊÍÆ÷ÄÜÖ±½ÓimportĬÈϰ²×°Â·¾¶ÒÔÍâµÄµÚÈý·½Ä£¿é£¿
ΪÁËÄÜimportĬÈϰ²×°Â·¾¶ÒÔÍâµÄµÚÈý·½µÄÄ£¿é£¨Èç×Ô¼ºÐ´µÄÄ£¿é£©£¬ÐèҪн¨PYTHONPATH»·¾³±äÁ¿£¬»·¾³±äÁ¿µÄÖµÉè ......
Python ×Ö·û´®
×Ö·û´®ÊÇ ×Ö·ûµÄÐòÁÐ ¡£×Ö·û´®»ù±¾ÉϾÍÊÇÒ»×éµ¥´Ê¡£
ÎÒ¼¸ºõ¿ÉÒÔ±£Ö¤ÄãÔÚÿ¸öPython³ÌÐòÖж¼ÒªÓõ½×Ö·û´®£¬ËùÒÔÇëÌØ±ðÁôÐÄÏÂÃæÕⲿ·ÖµÄÄÚÈÝ¡£ÏÂÃæ¸æËßÄãÈçºÎÔÚPythonÖÐʹÓÃ×Ö·û´®¡£
ʹÓõ¥ÒýºÅ£¨'£©
Äã¿ÉÒÔÓõ¥ÒýºÅָʾ×Ö·û´®£¬¾ÍÈçͬ'Quote me on this'ÕâÑù¡£ËùÓеĿհף¬¼´¿Õ¸ñºÍÖÆ±í·û¶¼ÕÕÔÑù±£Áô¡£ ......