[英]How to call a function in a class?
I try to call a function in a class from my Main()
我尝试从
Main()
调用类中的函数
Basically, I try to built an Employee
class with internal function. 基本上,我尝试构建具有内部功能的
Employee
类。 In my main, I try to call these function but it doesn't work. 在我的主机中,我尝试调用这些函数,但是它不起作用。
Am I missing something ? 我想念什么吗?
class Employee:
'Common base class for all employees'
empCount = 0
def __init__(self, name, salary):
self.name = name
self.salary = salary
Employee.empCount += 1
def displayEmployee(self):
print("Name : ", self.name, ", Salary: ", self.salary)
def test(self):
print("This is a test")
if __name__ == '__main__':
x = Employee("Maxime", 75000)
y = Employee("Sacha", 100000)
x.displayEmployee # Nothing appear in my console ?
x.test # Nothing appear in my console ?
Why doesn't the DisplayEmployee()
function print anything in my console? 为什么
DisplayEmployee()
函数不能在控制台中打印任何内容?
您应该不确定if __name__ == '__main__'
块,并且调用应为x.displayEmployee()
,注意括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.