[New-bugs-announce] [issue27738] odd behavior in creating list of lambda expressions

John Sahr report at bugs.python.org
Thu Aug 11 11:15:32 EDT 2016


New submission from John Sahr:

The following produces unexpected behavior.
I think that it should produce a list of six different lambda expressions,
but after creation, all six lambda expressions produce the same output.
It's possible that I'm missing something about Python.

##### begin example #######
from math import *

mm = []

for n in range(6):
    f = lambda x: sin(n*x)
    print f, f(1.0)
    mm.append(f)
    
print '***'

for m in mm:
    print m, m(1.0)
###### end example ####

----------
messages: 272454
nosy: John Sahr
priority: normal
severity: normal
status: open
title: odd behavior in creating list of lambda expressions
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27738>
_______________________________________


More information about the New-bugs-announce mailing list