2、怎么定义私有方法
在 Python 中定义私有变量只需要在变量名或函数名前加上“__”两个下划线
3、函数定义少了个实参,加个self即可
class C:
def myFun(self):
print('Hello!')
c = C()
c.myFun()
4、
class youleyuan():
chengren = 100
chengren67 = 120
haizi = 50
haizi67 = 60
def __init__(self, adult, child, day):
self.adult = adult
self.child = child
self.day = day
def piaojia(self):
if self.day in range(1,6):
self.c = self.adult * self.chengren + self.child * self.haizi
if self.day in range(6,8):
self.c = self.adult * self.chengren67 + self.child * self.haizi67
print(self.c)
A = youleyuan(2, 1, 5)#2成人1孩子周五
A.piaojia()