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?
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.
Read more about unpacking the tuple parameter (and why it was deleted) here: http://www.python.org/dev/peps/pep-3113/
. , - , .
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 :-)
Source: https://habr.com/ru/post/1708677/More articles:use svnant without username or password - svnWindows low-load I / O monitoring - processDeadlock check - javaКаков наилучший способ загрузки файлов конфигурации для разных версий одного и того же проекта на одном сервере? - phpПочему g++ жалуется при использовании шаблонов typedefs в graph_traits <>? - c++Import parts with specific metadata using MEF Preview 5 - c #Labeling and Safety Subversion - version-controlWndProc without visible form? - c #Pass variables between C ++ and Lua via Swig - c ++rake db: schema: dump does not provide data transfer information - is there an automated way to get this? - ruby-on-railsAll Articles