有人能解释一下为什么写这个代码是abc.name而不是mysillyobject.name吗
class Person:
def __init__(mysillyobject, name, age):
mysillyobject.name = name
mysillyobject.age = age
def myfunc(abc):
print("Hello my name is " + abc.name)
p1 = Person("John", 36)
p1.myfunc()
https://www.w3schools.com/python/gloss_python_self.asp
Tags:
输出:你好,我叫约翰
请参阅>; https://www.python.org/dev/peps/pep-0008/
这是由于第二个函数的输入参数为“abc”。如果将输入更改为“self”参数,则应使用self.name
相关问题 更多 >
编程相关推荐