PythonÖØÔØÑ§Ï°ÊÖ¼Ç
½ñÌìѧϰÁËÒ»ÏÂPythonµÄ²Ù×÷·ûÖØÔØ£¬×ܽáÁ˼¸µã±È½ÏÉñÆæµÄ¶«¶«£º
------------------------------------------------------------------------------------------------------------
¹ØÓÚiter£º
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, which is expected to return an iterator object. If it’s
provided,Python then repeatedly calls this iterator object’s next method to produce
items until a StopIteration exception is raised. If no such _ _iter_ _ method is found,
Python falls back on the _ _getitem_ _ scheme, and repeatedly indexes by offsets as
before, until an IndexError exception is raised.
ËùÒÔΪÁËʹÓÃiter£¬ÎÒÃDZØÐëÖØÔØ__iter__£¬È»ºóÔÙ¶¨ÒåÒ»¸önext·½·¨£¬Àý×ÓÈçÏ£º
class Squares:
def _ _init_ _(self, start, stop): # Save state when created
self.value = start - 1
self.stop = stop
def _ _iter_ _(self): # Get iterator object on iter( )
return self
def next(self): # Return a square on each iteration
if self.value == self.stop:
raise StopIteration
self.value += 1
return self.value ** 2
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
ÀûÓÃ__setattr__µÄʱºò£¬×Ô¼º¸³Öµ²»¿ÉÒÔʹÓÃself.name = value£¬ÒòΪÕâ¸öÓï¾äÒ²ÊÇÓÃÁË__setattr__
£¬ÕâÑùÖØ¸´Ê¹Ó㬳ö´í¡£ÒªÊ¹ÓÃself.__dict__['name'] = value
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
ÀûÓÃ__getattr__½¨Á¢“˽ÓД³ÉÔ±±äÁ¿£º
ÀûÓÃÖØÔØµÄ__setattr__ÔÚÿ´Îȡ֮ǰÅжÏÒ»ÏÂ˽ÓгÉÔ±Ãû×Öµ±ÖÐÓÐûÓУ¬À´ÊµÏÖ˽ÓУ¬´úÂëÈçÏ£¨È¡×Ô
Learning Python£©
class PrivateExc(Exception): pass
class Privacy:
&nb
Ïà¹ØÎĵµ£º
zz from ¡¶¿É°®µÄPython¡·
http://www.woodpecker.org.cn/
Python±ê×¼¿â http://www.woodpecker.org.cn:9081/doc/Python/_html/PythonStandardLib/
¼òÃ÷Python½Ì³Ì http://www.woodpecker.org.cn:9081/doc/abyteofpython_cn/chinese/index.html
Python¿ìËÙ½éÉÜ http://www.zoomquiet.org/share/s5/intropy/070322-intro ......
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
µ±È»ÄãÒ²¿ÉÒÔÔÚÊʵ ......
´Õ24ÊǾµäµÄÒæÖÇÓÎÏ·£¬¶àÍæ¿ÉÒÔʹÄÔ½îÁé»îÒ»µã£¬µ«Êǵ±Óöµ½ÎÞ½âµÄʱºò£¬¾Í»áºÜÉËÄԽΪ´Ë£¬Ð´¸ö³ÌÐòÀ´´úΪ¼ÆËã¡£
ÔËÐнá¹û£¬È¥³ýÁËÖØ¸´µÄһЩ±í´ïʽ£º
entry: 1
entry: 4
entry: 5
entry: 6
(4/(1-(5/6))) = 24
(6/((5/4)-1)) = 24
Press any key to exit...
entry: 3
entry: 3
entry: 8
entry: 8
(8/(3-(8 ......
1. µÚ¶þÕ Óï·¨¼°´úÂëÔ¼¶¨
&nb ......