class Test :
def foo1(self) :
print(id(self))
def foo2() :
print('foo4')
TestClass = Test()
TestClass.foo1()
Test.foo2()
""" =================================== """
TestClass.foo2()
Test.foo1()
If you write it like this, the code below will be error based on the perforation What is the difference between the code above and the code below based on the perforation?
python
First of all, you can't call the class right away, so you have to create a TestClass instance that specifies the TestClass like the code above.
Test.foo1() //Working
TestClass = Test()
TestClass.foo1() // Operated
In the class, the function needs to be self as the first factor to operate.p
So you have to fix the foo2() function like foo2(self)
This is a site where you can learn more about Python classes. It will be helpful if you read it
© 2024 OneMinuteCode. All rights reserved.