繁体   English   中英

当您将变量设置为方法时,您如何称呼该术语?

[英]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.randintrandint方法分配给变量foo

由于此方法不返回任何内容,因此 y 没有值,并且type()表示如此

你想要做的是使用y = button1.pack ,它将 function 分配给y

如果你在那之后在y上运行type() ,你会看到它返回它的类型为“函数”

暂无
暂无

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

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