python-037

0. 继承性

1. 对象

2. 默认自己?

3. __(在变量或者函数名前)

4. __init__

5. 没有默认的参数?


#-----定义一个游乐园门票的类-----#
class Ticket:
    workday_ticket = 100
    weekend_ticket = 1.2 * workday_ticket
    def workday(self, n):
        workday_money = self.workday_ticket * n
        print(workday_money)
    def weekend(self, n):
        weekend_money = self.weenkend_ticket * n
        print(weekend_money)
    def child_workday(self, n):
        child_workday_money = self.workday_ticket * 0.5
        print(child_workday_money)
    def child_weekend(self, n):
        child_weekend_money = self.weekend_ticket * 0.5
        print(child_weekend_money)

t = Ticket()
t1 = t.workday(2)
t2 = t.child_workday(1)
print(t1+t2)
发布了17 篇原创文章 · 获赞 0 · 访问量 1478

猜你喜欢

转载自blog.csdn.net/red_west/article/details/78513622