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

Python Ôª×é


Python Ôª×é
Ôª×éºÍÁбíÊ®·ÖÀàËÆ£¬Ö»²»¹ýÔª×éºÍ×Ö·û´®Ò»ÑùÊÇ ²»¿É±äµÄ ¼´Äã²»ÄÜÐÞ¸ÄÔª×é¡£Ôª×éͨ¹ýÔ²À¨ºÅÖÐÓöººÅ·Ö¸îµÄÏîÄ¿¶¨Òå¡£Ôª×éͨ³£ÓÃÔÚʹÓï¾ä»òÓû§¶¨ÒåµÄº¯ÊýÄܹ»°²È«µØ²ÉÓÃÒ»×éÖµµÄʱºò£¬¼´±»Ê¹ÓõÄÔª×éµÄÖµ²»»á¸Ä±ä¡£
ʹÓÃÔª×é
Àý9.2 ʹÓÃÔª×é
#!/usr/bin/python
# Filename: using_tuple.py
zoo = ('wolf', 'elephant', 'penguin')
print 'Number of animals in the zoo is', len(zoo)
new_zoo = ('monkey', 'dolphin', zoo)
print 'Number of animals in the new zoo is', len(new_zoo)
print 'All animals in new zoo are', new_zoo
print 'Animals brought from old zoo are', new_zoo[2]
print 'Last animal brought from old zoo is', new_zoo[2][2]
£¨Ô´Îļþ£ºcode/using_tuple.py£©
Êä³ö
$ python using_tuple.py
Number of animals in the zoo is 3
Number of animals in the new zoo is 3
All animals in new zoo are ('monkey', 'dolphin', ('wolf', 'elephant', 'penguin'))
Animals brought from old zoo are ('wolf', 'elephant', 'penguin')
Last animal brought from old zoo is penguin
ËüÈçºÎ¹¤×÷
±äÁ¿zooÊÇÒ»¸öÔª×飬ÎÒÃÇ¿´µ½lenº¯Êý¿ÉÒÔÓÃÀ´»ñÈ¡Ôª×éµÄ³¤¶È¡£ÕâÒ²±íÃ÷Ôª×éÒ²ÊÇÒ»¸öÐòÁС£
ÓÉÓÚÀ϶¯ÎïÔ°¹Ø±ÕÁË£¬ÎÒÃǰѶ¯ÎïתÒƵ½Ð¶¯ÎïÔ°¡£Òò´Ë£¬new_zooÔª×é°üº¬ÁËһЩÒѾ­ÔÚÄÇÀïµÄ¶¯ÎïºÍ´ÓÀ϶¯ÎïÔ°´ø¹ýÀ´µÄ¶¯Îï¡£»Øµ½»°Ì⣬עÒâÔª×éÖ®ÄÚµÄÔª×é²»»áʧȥËüµÄÉí·Ý¡£
ÎÒÃÇ¿ÉÒÔͨ¹ýÒ»¶Ô·½À¨ºÅÀ´Ö¸Ã÷ij¸öÏîÄ¿µÄλÖôӶøÀ´·ÃÎÊÔª×éÖеÄÏîÄ¿£¬¾ÍÏñÎÒÃǶÔÁбíµÄÓ÷¨Ò»Ñù¡£Õâ±»³Æ×÷ Ë÷Òý ÔËËã·û¡£ÎÒÃÇʹÓÃnew_zoo[2]À´·ÃÎÊnew_zooÖеĵÚÈý¸öÏîÄ¿¡£ÎÒÃÇʹÓÃnew_zoo[2][2]À´·ÃÎÊnew_zooÔª×éµÄµÚÈý¸öÏîÄ¿µÄµÚÈý¸öÏîÄ¿¡£
º¬ÓÐ0¸ö»ò1¸öÏîÄ¿µÄÔª×é¡£Ò»¸ö¿ÕµÄÔª×éÓÉÒ»¶Ô¿ÕµÄÔ²À¨ºÅ×é³É£¬Èçmyempty = ()¡£È»¶ø£¬º¬Óе¥¸öÔªËصÄÔª×é¾Í²»ÄÇô¼òµ¥ÁË¡£Äã±ØÐëÔÚµÚÒ»¸ö£¨Î¨Ò»Ò»¸ö£©ÏîÄ¿ºó¸úÒ»¸ö¶ººÅ£¬ÕâÑùPython²ÅÄÜÇø·ÖÔª×éºÍ±í´ïʽÖÐÒ»¸ö´øÔ²À¨ºÅµÄ¶ÔÏó¡£¼´Èç¹ûÄãÏëÒªµÄÊÇÒ»¸ö°üº¬ÏîÄ¿2µÄÔª×éµÄʱºò£¬ÄãÓ¦¸ÃÖ¸Ã÷singleton = (2 , )¡£
¸øPerl³ÌÐòÔ±µÄ×¢ÊÍ
ÁбíÖ®ÖеÄÁÐ±í²»»áʧȥËüµÄÉí·Ý£¬¼´ÁÐ±í²»»áÏñPerlÖÐÄÇÑù±»´òÉ¢¡£Í¬ÑùÔª×éÖеÄÔª×飬»òÁбíÖеÄÔª×飬»òÔª×éÖеÄÁбíµÈµÈ¶¼ÊÇÈç´Ë¡£Ö»ÒªÊÇPython£¬ËüÃǾÍÖ»ÊÇʹÓÃÁíÒ»¸ö¶ÔÏó´æ´¢µÄ¶ÔÏó¡£
Ôª×éÓë´òÓ¡Óï¾ä
Ôª×é×îͨ³£µÄÓ÷¨ÊÇÓÃÔÚ´òÓ¡Óï¾äÖУ¬ÏÂÃæÊÇÒ»¸öÀý×


Ïà¹ØÎĵµ£º

ÉæË®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ʵÏÖÍøÕ¾²âÊÔ

²âÊÔÍøÕ¾£ºBaiduÖ÷Ò³ÒÔ¼°Ïà¹ØµÄÒ³Ãæ
Ö÷Ì⣺ºÚºÐ²âÊÔ£¬¹¦ÄܲâÊÔ£¬ÐÔÄÜ/ѹÁ¦²âÊÔ£¬°²È«²âÊÔ£¬ Êý¾Ý×Öµä¹ÜÀí
1. ²âÊÔÒ³ÃæÊÇ·ñ¿É·ÃÎʵģ»
1.1 HTTP request status = 200, Ò³ÃæÏÂÔØÕýÈ·
from urllib import urlopen
# set up
url = None
# test
url = urlopen('http://www.baidu.com')
assert url.getcode() == 200
# ......

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·ÃÎÊ sql server

½ñÌìÊÔÑéʹÓÃpythonÁ¬½Ó sql server ·þÎñÆ÷¡£ÎҼǵÃÒÔǰʹÓÃadoÁ¬½Óaccess·Ç³£Ë³Àû£¬µ«ÊǽñÌìʹÓÃadoÁ¬½Ósql server¾¹È»²»³É¹¦¡£ÔÚpythonÀïÃæµÄ³ö´íÐÅÏ¢¶¼ÏÔʾΪתÒÆÐòÁУ¬·ÑÁË°ëÌì¾¢²Å¸ãÃ÷°×£ºÎÞЧµÄÀà±ð×Ö·û´®¡£
ÊÇÁ¬½Ó×Ö·û´®Â𣿲âÊÔÁ˺ü¸¸ö È·ÈÏÎÞÎóµÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®£¬Ò²ÊÇÈç´Ë ¡£ÉÏÍøËÑË÷£¬ÊÇÓпÉÄÜÊÇ comµÄÀà±ð×Ö ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ