code show as below:
---------------------------------------------------------------------------------------
*def generator():*
* while 1:*
* recv=yield a*
* print('recv :',recv)*
*if __name__=='__main__':*
* g=generator()*

*>>> a=10*
*>>> g.send(None)*
*10*
*>>> g.send(None)*
*recv : None*
*10*
*>>> a=11*
*>>> g.send('next')*
*recv : next*
*11*
*>>> *
*-------------------------------------------------------------------------------------------*
*Why do you claim that its internal variable a, even if it is not declared, 
does not report an error, and can access the external variable of the same 
name --a. This makes me puzzled. Can anyone tell me why?*

Reply via email to