python - 当您将变量设置为方法时,您将术语称为什么?
问题描述
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
,它将将该功能分配给y
如果你type()
在y
那之后继续运行,你会看到它返回它的类型为“函数”
推荐阅读
- javascript - 如何使用 Typescript 键入 ref 参数
- javascript - 如何获取跨度类标题值的值
- json - 来自寄存器变量的 ansible 访问项目
- database - 如何使用 Oracle dbms_ldap 或 dbms_ldap_utl 从 LDAP 获取操作属性?
- html - Span asp-validation-for 不一致?
- karate - 空手道 - 嵌套 JSON 对象模式验证导致空手道异常
- python - 给定任意两点之间的距离时如何对点进行聚类?
- excel - VBA Word:执行 While 循环
- sql - 大查询 - 使用关键字 @run_date 在外部分区表上安排查询
- kotlin - 一种在 kotlin 中锁定对特定资源的访问的简单方法