[英]What do you call the term when you set the variable to a method?
from tkinter import *
root = Tk()
button1 = Button(root, text= "Hello world click here to close")
y = button1.pack()
print (type (y))
root.mainloop()
将y
设置为button1.pack()
时,您如何称呼该技术?为什么它会返回“<class 'NoneType'>”?
y = button1.pack()
将y
设置为pack()
方法的预期返回值。
例如,
foo = random.randint()
将foo
设置为randint
方法返回的随机数。
然而, foo = random.randint
将randint
方法分配给变量foo
由于此方法不返回任何内容,因此 y 没有值,并且type()
表示如此
你想要做的是使用y = button1.pack
,它将 function 分配给y
如果你在那之后在y
上运行type()
,你会看到它返回它的类型为“函数”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.