What is the signature of exotic functions in Python?

I recently saw a link to "exotic signatures" and the fact that they are deprecated in version 2.6 (and removed in version 3.0). The given example:

def exotic_signature((x, y)=(1,2)): return x+y

What makes this "exotic" signature?

+3
source share
3 answers

What an exotic thing is that x and y are one function argument, which is unpacked into two values ​​... x and y. This is equivalent to:

def func(n):
    x, y = n
    ...

Both functions require a single argument (list or tuple) that contains two elements.

+6
source

Read more about unpacking the tuple parameter (and why it was deleted) here: http://www.python.org/dev/peps/pep-3113/

+6

. , - , .

points = [(1,2), (-3,1), (4,-2), (-1,5), (3,3)]

, . ​​:

def magnitude((x,y)):
    return (x**2 + y**2)**0.5

(0,0) :

map(magnitude, points)

... well, at least you could in python 2.x :-)

+1
source

Source: https://habr.com/ru/post/1708677/


All Articles