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

[Python ѧϰ]2.5°æyield֮ѧϰÐĵÃ

(ת)[Python ѧϰ]2.5°æyield֮ѧϰÐĵÃ
 
ÔÚ shhgs ·¢²¼Á˹ØÓÚ¡¶ Py 2.5 what's new Ö® yield¡·Ö®ºó£¬Ô­À´ÎÒ²»ÊÇÌØ±ð¹Ø×¢ yield µÄÓ÷¨£¬ÒòΪ¶ÔÓÚ2.3ÖмÓÈëµÄyieldÏà¶ÔÀ´Ëµ¹¦Äܼòµ¥£¬ËüÊÇ×÷Ϊһ¸ö generator ²»¿ÉȱÉÙµÄÒ»ÌõÓï¾ä£¬Ö»Òª°üº¬ËüµÄº¯Êý¼´ÊÇÒ»¸ö generator ¡£µ«ÔÚ2.3ÖУ¬generator ²»ÄÜÖØÈ룬²»ÄÜÔÚÔËÐйý³ÌÖÐÐ޸쬲»ÄÜÒý·¢Òì³££¬ÄãҪôÊÇ˳Ðòµ÷Óã¬ÒªÃ´¾Í´´½¨Ò»¸öÐ嵀 generator¡£¶øÇÒ generator ÖÐµÄ yield Ö»ÊÇÒ»¸öÓï¾ä¡£µ«µ½ÁË 2.5 °æÖ®ºó£¬Çé¿ö·¢ÉúÁ˺ÜÔڵı仯¡£
ÔÚ shhgs µÄÎÄÕÂÖжÔÓÚ yield ²¢Ã»ÓÐ×öÌ«¶àµÄÃèÊö£¬Ò²Òò´ËÈÃÎÒÔÚÀí½âÉϲúÉúÁËÐí¶àÎÊÌ⣬ÓÚÊÇÎÒ×ÐϸµØÑо¿ÁË What's new ºÍ PEP 342 Îĵµ£¬ÓÐÁËһЩÌå»á£¬ÃèÊöÔÚÏÂÃæ¡£
ÕâÀﲻ˵ΪʲôҪ¶Ô yield ½øÐÐÐ޸ģ¬Ö»Ëµ¹¦ÄÜ¡£
1. yield ³ÉΪÁ˱í´ïʽ£¬Ëü²»ÔÙÊÇÓï¾ä£¬µ«¿ÉÒÔ·ÅÔÚµ¥¶ÀµÄÐÐÉÏ¡£Ô­ÎÄ£º
Redefine "yield" to be an expression, rather than a statement. The current yield statement would become a yield expression whose value is thrown away.
¿ÉÒÔ¿´µ½£¬Èç¹ûÄ㻹ÊÇд³ÉÓï¾äÐÎʽµÄ»°£¬Æäʵ»¹ÊÇÒ»¸ö±í´ïʽ£¬Ö»ÊÇËüµÄÖµ±»ÈÓµôÁË¡£
ÄÇôһ¸ö yield ±í´ïʽ¿ÉÒÔÕâÑùд£º
x = yield i
y = x + (yield x)
ÄÇôÕâÖÖ»úÖÆµ½µ×ÊÇÈçºÎ¹¤×÷µÄÄØ£¿ÔÚ2.3°æºÜÈÝÒ×Àí½â£¬ÄãÍêÈ«¿ÉÒÔ°Ñ yield Óï¾äÀí½âΪһ¸ö "return" Óï¾ä£¬Ö»²»¹ý "return" Íêºó£¬º¯Êý²¢²»½áÊø£¬¶øÊǶÏÐøÔËÐУ¬Ö±µ½ÔÙ´ÎÓöµ½ yield Óï¾ä¡£ÄÇôµ½ÁË 2.5 °æ²»½ö½öÊÇÒ»¸ö "return" Óï¾äÄÇô¼òµ¥ÁË£¬ÈÃÎÒÃÇ¿´ÍêÏÂÃæ¹ØÓÚ send() µÄ˵Ã÷ÔÙÃèÊöËü°É¡£
2. Ôö¼ÓÁË send(msg) ·½·¨£¬Òò´ËÄã¿ÉÒÔʹÓÃËüÏò generator ·¢ËÍÏûÏ¢¡£Ô­ÎÄ£º
Add a new send() method for generator-iterators, which resumes the generator and "sends" a value that becomes the result of the current yield-expression. The send() method returns the next value yielded by the generator, or raises StopIteration if the generator exits without yielding another value.
Ö´ÐÐÒ»¸ö send(msg) »á»Ö¸´ generator µÄÔËÐУ¬È»ºó·¢Ë͵ÄÖµ½«³ÉΪµ±Ç° yield ±í´ïʽµÄ·µ»ØÖµ¡£È»ºó send() »á·µ»ØÏÂÒ»¸ö±» generator yield µÄÖµ£¬Èç¹ûûÓÐÏÂÒ»¸ö¿ÉÒÔ yield µÄÖµÔòÒý·¢Ò»¸öÒì³£¡£
ÄÇô¿ÉÒÔ¿´¹ýÕâÆäʵ°üº¬ÁËÒ»´ÎÔËÐУ¬´Ó½«msg¸³¸øµ±Ç°±»Í£×¡µÄ yield ±í´ïʽ¿ªÊ¼£¬µ½ÏÂÒ»¸ö yield Óï¾ä½áÊø£¬È»ºó·µ»ØÏÂÒ»¸öyieldÓï¾äµÄ²ÎÊý£¬È»ºóÔÙ¹ÒÆ


Ïà¹ØÎĵµ£º

pythonÖеÄÁбíÅÅÐò²Ù×÷

 
 
 
Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.
There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various man ......

Python IDE and GUI Framework for Windows

Pythonwin - Python IDE and GUI Framework for Windows.
Copyright 1994-2006 Mark Hammond
Python is Copyright (c) 2000-2008 ActiveState Software Inc.
Copyright (c) 2001-2008 Python Software Foundation.
All Rights Reserved.
Copyright (c) 2000 BeOpen.com.
All Rights Reserved.
Copyright (c) 1995-20 ......

pythonѧϰ

3¡¢Lists Êý¾ÝÀàÐÍ
 
    ÔÚpythonÖУ¬listsÊÇÐòÁÐÈÝÆ÷£¬Ëü¿ÉÒÔÈÝÄÉÈκÎÀàÐ͵ĶÔÏ󡣺Ístrings²»Í¬£¬ListsÖ§³ÖÔ­µØÐÞ¸Ä(mutalbe in place),ͨ¹ýϱêÒýÓõķ½Ê½£¬¿ÉÒÔÐÞ¸ÄListsµÄÄÚÈÝ£¬ÈçpÊÇLists¶ÔÏó£¬ Ôò¿ÉÒÔͨ¹ýp[1] = '123'ÕâÖֵķ½Ê½¸Ä±äpµÄÄÚÈÝ¡£
   ListsÊÇÐòÁÐÈÝÆ÷£¬Ö§³ÖÈκÎÐòÁÐ ......

PythonÍêÈ«ÐÂÊֽ̳Ì

http://www.cppblog.com/oosky/archive/2005/10/11/639.html
Lesson 1 ×¼±¸ºÃѧϰPythonµÄ»·¾³
Python µÄ¹Ù·½ÍøÖ·£º
www.python.org
µã»÷ÏÂÃæÁ¬½Ó¾Í¿ÉÒÔÖ±½ÓÏÂÔØÁË£¬ÕâÀïÖ»ÌṩÁËWindowsϵÄPython¡£
http://www.python.org/ftp/python/2.4.2/python-2.4.2.msi
linux°æ±¾µÄÎҾͲ»ËµÁË£¬ÒòΪÈç¹ûÄãÄܹ»Ê¹ÓÃlinux²¢°²×° ......

pythonÄ£¿éÖ®smtplib: ÓÃpython·¢ËÍSSL/TLS°²È«Óʼþ

pythonµÄsmtplibÌṩÁËÒ»Öֺܷ½±ãµÄ;¾¶·¢Ë͵ç×ÓÓʼþ¡£Ëü¶ÔsmtpЭÒé½øÐÐÁ˼òµ¥µÄ·â×°¡£
     smtpЭÒéµÄ»ù±¾ÃüÁî°üÀ¨£º
         HELO Ïò·þÎñÆ÷±êʶÓû§Éí·Ý
         MAIL ³õʼ»¯Óʼþ´«Êä mail from:
 &nb ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ