简体   繁体   English

将元组传递给Python函数

[英]Passing tuple to a Python function

I know that there has been a bit of discussion about passing a tuple to a function; 我知道关于将元组传递给函数的讨论很多。 I checked all of them but couldn't solve my problem. 我检查了所有这些,但无法解决我的问题。 So here is the problem. 所以这就是问题所在。 I am trying to pass two tuples into a function and do calculations on them. 我试图将两个元组传递给一个函数,并对它们进行计算。 Here is a sample: 这是一个示例:

c=(2,3)
d=(4,5)

def func1((a(0),a(1)),(b(0),b(1))):
    return(a(0)*b(1))

I also tried 我也试过

c=(2,3)
d=(4,5)

def func1(a,b):
    return(a(0)*b(1))

Both of them give error invalid syntax or 'tuple' object is not callable . 它们都给出错误的invalid syntax或者'tuple' object is not callable Any help is appreciated. 任何帮助表示赞赏。 Please read it carefully before marking it "duplicate". 在将其标记为“重复”之前,请仔细阅读。 Thank you. 谢谢。

First example is invalid python syntax. 第一个示例是无效的python语法。 Second, index access uses square brackets. 其次,索引访问使用方括号。

def func1(a,b):
    return(a[0] * b[1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM