Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kivy python*参数_Python_Function_Kivy_Args - Fatal编程技术网

Kivy python*参数

Kivy python*参数,python,function,kivy,args,Python,Function,Kivy,Args,我刚刚学习了kivy,我不理解本教程中调用方的一些参数: 我知道*arg是传递给调用者的对象列表。但在这个功能中: class Ex18(BoxLayout): def newWeights(self, *args): t = args[1] self.ids['w0'].value = (1-t)**3 self.ids['w1'].value = 3*t*(1-t)**2 self.ids['w2'].value =

我刚刚学习了kivy,我不理解本教程中调用方的一些参数:

我知道*arg是传递给调用者的对象列表。但在这个功能中:

class Ex18(BoxLayout):
    def newWeights(self, *args):
        t = args[1]
        self.ids['w0'].value = (1-t)**3
        self.ids['w1'].value = 3*t*(1-t)**2
        self.ids['w2'].value = 3*t**2*(1-t)
        self.ids['w3'].value = t**3
args[1]是什么意思

这个打电话的人用KV语言说:

on_value: root.newWeights(*args)

此调用者中的*arg是什么。哪些参数被传递到此中,它不是显式的。希望你明白我的意思,我的英语不好。非常感谢

*args
允许您向函数传递任意数量的参数,它是传递给函数的参数元组

def foo(*args):
    for i in args:
        print i
    print type(args)

foo(1, 2, 3,'a')

output:-
>>> 
1
2
3
a
<type 'tuple'>
虽然不需要它,就像您知道nombers参数传递给函数调用一样

def foo(a, b, c, d, e):
    print a, b, c, d, e

foo(1, 2, 'this is','string', [1, 2 ,3, 4])


>>> 
1 2 this is string [1, 2, 3, 4]

*args
仍然是您在这里描述的内容:它是一个元组,包含给定给newWeigts的位置参数。它使用args[1]并丢弃args[0]似乎有点奇怪,而且它确实不是很明确。谢谢,但我不明白这一点。on_value:root.newWeights(*args)what*args在这里。例如,如果它像这样调用函数:newWeights(a,b,c),我会理解。。。但是这个文档中的*args是什么呢?@T–mQuangVũ在该文档中,滑块负责调用根类中的newWeights函数,
*args
携带
根类中的
newWeights
函数的参数,我认为在
kivy
on_value
中存储
newWeights
的函数定义。这意味着on_value将传递*args newWeights,我不知道这个元组中的哪个变量。例如,def newWeights(self,*args):t=args[1]。此函数中的参数[1]。我认为它是Slider类中的“value”变量,但我想知道它的规则是什么。我在Kivy文档中搜索了好几个小时,但是我找不到它。文档说你需要调用带有任何参数名称的
newWeight
函数,然后它只是通过
arg tuple
的第一个索引值给字典键“id”加上一些权重(值)。我仍然不明白:(.让我更清楚地解释我的问题。我只是在互联网上搜索,on_值不存储newWeights函数,因此我将on_值函数调用newWeights函数作为其参数,如下所示:on_值(newWeights,*args)。在Slider类中有一些变量和方法,包括on_value、value、max、min…blablabla。在函数newWeights中,i guest args[1]是类滑块的值。我不明白这一点。..args[1]=value只是我的guest。我不知道函数中哪个是args[1],以及*arg引用了什么。
arg[0] = first element of tuple
arg[1] = second element of tuple
.
.
and so on
def foo(a, b, c, d, e):
    print a, b, c, d, e

foo(1, 2, 'this is','string', [1, 2 ,3, 4])


>>> 
1 2 this is string [1, 2, 3, 4]