python_¸´ÔÓÊý¾ÝÀàÐÍ
python_¸´ÔÓÊý¾ÝÀàÐÍ
pythonÖÐÔÉúµÄ¶ÓÁÐÓÐ2ÖÖ£¬Ò»ÖÖÊÇÆÕͨµÄ¶ÓÁÐ(Queue)£¬Ò»ÖÖ½Ð×öÓÅÏȶÓÁÐ(PriorityQueue)£¬¼´Ð¡µÄÏȳöÁС£
×¢Ò⣺¶ÓÁÐÊÇḬ̈߳²È«µÄ£¬python 3.0ÖÐÖ§³Ö¶à½ø³Ì£¬Ò²ÓÐÀàËƵÄQueue£¬µ«²»ÊÇÕâ¸ö¡£
1Õ»¡¢¶ÓÁС¢¶Ñ
pythonÖÐÔÉúµÄ¶ÓÁÐÓÐ2ÖÖ£¬Ò»ÖÖÊÇÆÕͨµÄ¶ÓÁÐ(Queue)£¬Ò»ÖÖ½Ð×öÓÅÏȶÓÁÐ(PriorityQueue)£¬¼´Ð¡µÄÏȳöÁС£
×¢Ò⣺¶ÓÁÐÊÇḬ̈߳²È«µÄ£¬python 3.0ÖÐÖ§³Ö¶à½ø³Ì£¬Ò²ÓÐÀàËƵÄQueue£¬µ«²»ÊÇÕâ¸ö¡£
¹¹Ô캯Êý£º
queue.Queue(maxsize)
queue.LifoQueue(maxsize)
queue.PriorityQueue(maxsize)
Òì³££º
queue.Empty
queue.Full
·½·¨£º
qsize() »ñµÃ¶ÓÁеĴóС
put_nowait(item) Èë¶Ó
get_nowait() ³ö¶Ó
2 ¼¯ºÏ
´´½¨¼¯ºÏ
set(list)
set(tuple)
Ìí¼ÓÔªËØ:set.add(element)
ɾ³ýÔªËØ:set.remove(element)
set.discard(element) #Èç¹û´æÔÚ£¬É¾³ý
set.pop() #Ëæ»úɾ³ýÔªËØ
Çå¿Õ¼¯ºÏ:set.clear()
¼¯ºÏ²Ù×÷£º
°üº¬<=
Õæ°üº¬<
²¢union(set1,set2,...)
|
½»intersection
&
²îdifference
-
Ïà¹ØÎĵµ£º
1¡¢ÔÚPythonÖÐ×î»ù±¾µÄÊý¾Ý½á¹¹ÊÇÐòÁУ¨sequence£©£¬ÐòÁÐÖеÄÿ¸öÔªËر»·ÖÅäÒ»¸öÊý×Ö——ÔªËصÄλÖã¬Ò²½ÐË÷Òý¡£µÚÒ»¸öË÷ÒýÊÇ 0£¬µÚ¶þ¸öË÷ÒýÊÇ1£¬Èç´ËµÝÍÆ¡£ÐòÁÐÖеÄ×îºóÒ»¸öÌõÄ¿±»±ê¼ÇΪ-1£¬µ¹ÊýµÚ¶þÊÇ-2£¬Èç´ËµÝÍÆ¡£
2¡¢ÐòÁУºeg:edward = ['Edward Gumby', 42]£¬ÐòÁÐÒ²ÄÜ°üº¬ÆäËûµÄÐòÁС£Ð ......
while µÄÓ÷¨£º
while ºóÃæ¸úÌõ¼þ±í´ïʽ£¬(:)ºóÃæ¸úÓï¾ä¿é£¬Äã¿ÉÒÔÔÚÕâ¶ÎÓï¾ä¿éÀïÐÞ¸ÄÌõ¼þ±í´ïʽµÄijЩ±äÁ¿£¬µ±Ìõ¼þ±í´ïʽ Ϊ¼ÙµÄʱºòÍ˳öÑ»·¡£ÀýÈ磺
flag = 5
while flag > 0:
#ÕâÀïÊÇÄãµÄ´úÂë
flag -= 1
#if flag == 3: break
#if flag == 3: continue
print flag
µ±È»ÄãÒ²¿ÉÒÔÔÚÊʵ ......
(1).µ±"print os.path.dirname(__file__)"ËùÔڽű¾ÊÇÒÔÍêÕû·¾¶±»ÔËÐеģ¬ ÄÇô½«Êä³ö¸Ã½Å±¾ËùÔÚµÄÍêÕû·¾¶£¬±ÈÈ磺
python d:\pythonSrc\test\test.py
&nb ......
1.1. Óï·¨
1.1.1. if
>>> x=int(raw_input("please enter an integer:"))
please enter an integer:-8
>>> if x<0:
... print 'negative'
... elif x==0:
... print 'zero'
... else:
... print 'positive'
...
negative
ÕâÀïÓм¸¸ö֪ʶµãÐèÒªÌáÐÑ£º
1¡£ºÍ ......