代码如下:
__author__ = 'chester'
class Customer():
name=''
balance=0
def find_imfor():
print('name:' + name)
print('balance:' + str(balance))
customer=Customer()
customer.find_imfor()
运行提示:TypeError: find_imfor() takes 0 positional arguments but 1 was given
类方法里缺少self关键字,修改后
__author__ = 'chester'
class Customer():
name=''
balance=0
def find_imfor(self):
print('name:' + self.name)
print('balance:' + str(self.balance))
customer=Customer()
customer.find_imfor()
运行结果
C:\Users\chester\AppData\Local\Programs\Python\Python36\python.exe D:/py/cc/c.py
name:
balance:0
Process finished with exit code 0