0

I'm new here, so if this isn't the right place for this, just let me know and I'll move :)

So I'm just learning python, and reading the tutorial
python tutorial
and I don't really get this part. The first (seq = 0,1,2...,8) is fine, but then how does map know to use seq,seq as x,y. It seems as though add is written again as a variable, but it is used as a function. I've never seen this without brackets {add() or add(seq,seq)}. Also, does map always take each successive argument as the argument in its included function (in this example, does map always take the first seq as add's x, and the second seq as add's y?)

>>> seq = range(8)
>>> def add(x, y): return x+y
...
>>> map(add, seq, seq)
[0, 2, 4, 6, 8, 10, 12, 14]

Thanks in advance
-Brandon

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Gribouillis
0

add is a variable which value is a function. In the same way, if you write z = 0.0 , then z is a variable which value is a float. The difference is that add has the special property that its "callable" with the syntax add(x, y) . You can check this

>>> callable(add)
True

Try typing

>>> help(map)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.