pythonÄ£¿é
¼ò½é
ÄãÒѾѧϰÁËÈçºÎÔÚÄãµÄ³ÌÐòÖж¨ÒåÒ»´Îº¯Êý¶øÖØÓôúÂë¡£Èç¹ûÄãÏëÒªÔÚÆäËû³ÌÐòÖÐÖØÓúܶຯÊý£¬ÄÇôÄã¸ÃÈçºÎ±àд³ÌÐòÄØ£¿Äã¿ÉÄÜÒѾ²Âµ½ÁË£¬´ð°¸ÊÇʹÓÃÄ£¿é¡£Ä£¿é»ù±¾ÉϾÍÊÇÒ»¸ö°üº¬ÁËËùÓÐÄ㶨ÒåµÄº¯ÊýºÍ±äÁ¿µÄÎļþ¡£ÎªÁËÔÚÆäËû³ÌÐòÖÐÖØÓÃÄ£¿é£¬Ä£¿éµÄÎļþÃû±ØÐëÒÔ.pyΪÀ©Õ¹Ãû¡£
Ä£¿é¿ÉÒÔ´ÓÆäËû³ÌÐò ÊäÈë ÒÔ±ãÀûÓÃËüµÄ¹¦ÄÜ¡£ÕâÒ²ÊÇÎÒÃÇʹÓÃPython±ê×¼¿âµÄ·½·¨¡£Ê×ÏÈ£¬ÎÒÃǽ«Ñ§Ï°ÈçºÎʹÓñê×¼¿âÄ£¿é¡£
ʹÓÃsysÄ£¿é
#!/usr/bin/python
#filename:sys.py
import sys
print "the command line arguments are:"
for i in sys.argv:
print i
print ' The PYTHONPATH is', sys.path, ' '
Êä³ö½á¹ûÊÇ£º
windyang@windyang-desktop:~/python$ python sys.py
the command line arguments are:
sys.py
The PYTHONPATH is ['/home/windyang/python', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages']
ËüÈçºÎ¹¤×÷
Ê×ÏÈ£¬ÎÒÃÇÀûÓÃimportÓï¾ä ÊäÈë sysÄ£¿é¡£»ù±¾ÉÏ£¬Õâ¾äÓï¾ä¸æËßPython£¬ÎÒÃÇÏëҪʹÓÃÕâ¸öÄ£¿é¡£sysÄ£¿é°üº¬ÁËÓëPython½âÊÍÆ÷ºÍËüµÄ»·¾³Óйصĺ¯Êý¡£
µ±PythonÖ´ÐÐimport sysÓï¾äµÄʱºò£¬ËüÔÚsys.path±äÁ¿ÖÐËùÁÐĿ¼ÖÐÑ°ÕÒsys.pyÄ£¿é¡£Èç¹ûÕÒµ½ÁËÕâ¸öÎļþ£¬Õâ¸öÄ£¿éµÄÖ÷¿éÖеÄÓï¾ä½«±»ÔËÐУ¬È»ºóÕâ¸öÄ£¿é½«Äܹ»±»Äã ʹÓà ¡£×¢Ò⣬³õʼ»¯¹ý³Ì½öÔÚÎÒÃÇ µÚÒ»´Î ÊäÈëÄ£¿éµÄʱºò½øÐС£ÁíÍ⣬“sys”ÊÇ“system”µÄËõд¡£
sysÄ£¿éÖеÄargv±äÁ¿Í¨¹ýʹÓõãºÅÖ¸Ã÷——sys.argv——ÕâÖÖ·½·¨µÄÒ»¸öÓÅÊÆÊÇÕâ¸öÃû³Æ²»»áÓëÈκÎÔÚÄãµÄ³ÌÐòÖÐʹÓõÄargv±äÁ¿³åÍ»¡£ÁíÍ⣬ËüÒ²ÇåÎúµØ±íÃ÷ÁËÕâ¸öÃû³ÆÊÇsysÄ£¿éµÄÒ»²¿·Ö¡£
sys.argv±äÁ¿ÊÇÒ»¸ö×Ö·û´®µÄ ÁÐ±í £¨Áбí»áÔÚºóÃæµÄÕ½ÚÏêϸ½âÊÍ£©¡£ÌرðµØ£¬sys.argv°üº¬ÁË ÃüÁîÐвÎÊý µÄÁÐ±í£¬¼´Ê¹ÓÃÃüÁîÐд«µÝ¸øÄãµÄ³ÌÐòµÄ²ÎÊý¡£
ÕâÀµ±ÎÒÃÇÖ´ÐÐpython using_sys.py we are argumentsµÄʱºò£¬ÎÒÃÇʹÓÃpythonÃ
Ïà¹ØÎĵµ£º
1¡¢PythonÖ®ÖÐΨһÄÚ½¨µÄÓ³ÉäÀàÐ;ÍÊÇ×ֵ䣨Dictionary£©¡£×ÖµäÖеÄÖµ²¢Ã»ÓÐÌØÊâµÄ˳Ðò£¬µ«ÊǶ¼°´Õչؼü×Ö£¨Key£©½øÐд洢£¬¹Ø¼ü×Ö¿ÉÒÔÊÇÊý×Ö¡¢×Ö·û´®£¬ÉõÖÁÊÇÔª×飨Tuple£©¡£
2¡¢×ÖµäµÄÓï·¨£º×ÖµäÃû = {'¼ükeys':'Öµvaules','¼ükeys':'Öµvaules','¼ükeys':'Öµvaules',...}£¬×ÖµäÖаüº¬ºÜ¶à¶Ô£¨³ÆΪÌõÄ¿items£©£¬ÓÉ£¨keys£ ......
ÏîÄ¿ÐèÒª£¬¸Õ¸Õ½Ó´¥python¡£
½ñÌì¿´Êé¿´µ½a>b==c £¬a,b,cΪinteger
ÔÚC/C++/C#ÖУ¬a>bΪboolean,²»¿ÉÓëinteger±È½ÏÏàµÈ
µ«python a>b==cµÈЧÓÚ((a>b)&&(b==c))
ÔÚpythonÖеÄд·¨ÊÇa>b and b==c ......
Ç°Ò»ÕóÔÚдһ¸ö×Ô¶¯²âÊÔ³ÌÐòʱÐèÒª°´ÕÕÌض¨×Ö·û¶ÔÊÕµ½µÄÊý¾Ý½øÐÐÖ¡µÄ·Ö¸î£¬ÔÓÐÒªÇóÊÇÓÐÿ֡ǰºó¸÷ÓÐÒ»¸öͬÑùµÄÌØÊâ×Ö·û,µ±Ê±¹À¼ÆÏÂʱ¼ä»¹¹»£¬Ï뽫ÆäÀ©Õ¹ÎªÒ»¸ö½ÏΪͨÓù¦ÄÜ£¬¼´Ã¿Ö¡Êý¾ÝÇ°Óи÷ÓÐÒ»¸öÌØÊâ×Ö·û±íʾ¿ªÊ¼ºÍ½áÊø£¬µ«Ç°ºóÕâÁ½×Ö·û¿ÉÒÔ²»Í¬£¬Ò²¿ÉÒÔÖ»ÓÐÒ»¸ö£¨ÔÚÍ·ÔÚβ·Ö¸îЧ¹û²»Í¬£©£¬Í¬Ê±Ñ§Ï°ÁËÒ»Õópython£¬¸Ð¾õÆ ......
1¡¢Ê¹ÓÃdef¶¨Ò庯Êý
2¡¢º¯ÊýÎĵµ£ºÔÚº¯ÊýµÄ¿ªÍ·Ð´ÏÂ×Ö·û´®£¬Ëü¾Í»á×÷Ϊº¯ÊýµÄÒ»²¿·Ö½øÐд洢£¬³ÆΪ"Îĵµ×Ö·û´®"¡£
ÄÚ½¨µÄ½Ð×öhelpµÄº¯Êý·Ç³£ÓÐÓÃ,Èç¹ûÄãÔÚ½»»¥Ê½½âÊÍÆ÷ÖÐʹÓã¬Äã¿ÉÒԵõ ......