why Python can't define tuples in a function?

PythonServer Side ProgrammingProgramming

Since Python 3.0, it is no longer possible to define unpacked tuple as a parameter in a function (PEP 3113). It means if you try to define a function as below −

def fn(a,(b,c)):

Python interpreter displays syntax error at first bracket of tuple. Instead, define tuple objects as parameter and unpack inside the function. In following code, two tuple objects representing x and y coordinates of two points are passed as parameters to calculate distance between the two. Before calculating, the tuple objects are unpacked in respective x and y coordinates.

def hypot(p1,p2):
   import math
   return hyp

print ("hyp=",hypot(x,y))
Published on 02-Jan-2018 23:40:43