【Py】函数参数是元组怎么处理

如果想写出如下函数: 

1 def MyFun((x, y), (a, b)):
2     return x * y - a * b
3 ======
4 SyntaxError: invalid syntax

运行的结果肯定是报错,因为函数的参数必须是变量,而元组并不是变量,可以通过如下的手段进行处理:

1 def multiple(x,y):
2     result = x[0]*x[1] - y[0]*y[1]
3     print(result)
4 multiple((5,6),(3,4))
5 ======
6 18

 

 

 

 

 

 

posted @ 2016-03-19 17:07  喜闻乐见小逗逗  阅读(490)  评论(0)    收藏  举报