#a class is created on here
class Employee:
raise_amount=1.04
def __init__(self, first, last, pay):
self.k=first
self.p=last
self.l=pay
self.email=first+'.'+last+'@gmail.com'
self.h=self.email
def fullname(self):
return ('{} {}'.format(self.k,self.p))
def fullname1(self):
return print('{} {}'.format(self.k,self.p))
def fullname2(self):
print('{} {}'.format(self.k,self.p))
def apply_raise(self):
self.l=self.l*self.raise_amount
emp1= Employee('Aditya', 'Shrivastava', 5000000)
print(emp1.fullname())
print(emp1.fullname1())
emp1.fullname1()
emp1.fullname2()
print(emp1.fullname2())
输出结果如下:
Aditya Shrivastava
Aditya Shrivastava
无
Aditya Shrivastava
Aditya Shrivastava
Aditya Shrivastava
没有
答案 0 :(得分:2)
看看这个例子:
class Employee:
def none_funct(self):
return print("hello")
emp1= Employee('Aditya', 'Shrivastava', 5000000)
print(emp1.none_funct())
打印:
hello
None
为什么呢?我认为,print
是一个执行动作并返回None
的函数,所以这里:
print(emp1.none_funct())
在print
内,您有emp1.none_funct()
打印“hello”,但返回None
,而外部print
打印出无