• python基础之面向对象OOP


    #类(面向对象)  PageObject设计模式  unittest 知识体系

    #函数式编程
    import datetime
    book_info = {
    "title":"Python",
    "price":"33.1",
    "auther":"毛桃",
    "publisher":"北京大学",
    "pubdate":datetime.datetime.today()
    }

    def seacher_book(book):
    print("这本书的主题是:{}".format(book_info["title"]))
    print("这本书的价格是:{}".format(book_info["price"]))
    print("这本书的作者是:{}".format(book_info["auther"]))
    print("这本书的出本社是:{}".format(book_info.get("publisher")))
    print("这本书的出版时间是:{}".format(book_info.get("pubdate")))
    #
    # if __name__ == '__main__':
    # seacher_book(book_info)

    #构造方法
    # class Book:
    # def __init__(self,title,author,price,publisher,pubdate):
    # self.title = title
    # self.author = author
    # self.price = price
    # self.publisher = publisher
    # self.pubdate = pubdate
    #
    # book = Book("Selenium",'Teacher',"43.33","清华大学",datetime.datetime.today())
    # print(book.title)
    # print(book.author)
    # print(book.price)
    # print(book.publisher)
    # print(book.pubdate)

    #类构造函数
    # class Book:
    # def __init__(self,title,author,price,publisher,pubdate):
    # self.title = title
    # self.author = author
    # self.price = price
    # self.publisher = publisher
    # self.pubdate = pubdate
    #
    # def seacher_book(self):
    # print("这本书的主题是:{}".format(self.title))
    # print("这本书的价格是:{}".format(self.price))
    # print("这本书的作者是:{}".format(self.author))
    # print("这本书的出本社是:{}".format(self.publisher))
    # print("这本书的出版时间是:{}".format(self.pubdate))
    #
    # if __name__ == '__main__':
    # book = Book("Selenium",'Teacher',"43.33","清华大学",datetime.datetime.today())
    # book.seacher_book()

    #默认值的写法
    # class Book:
    # def __init__(self,
    # title = "Appium测试",
    # author = "",
    # price = 0.0,
    # publisher = None,
    # pubdate = datetime.datetime.now()):
    # self.title = title
    # self.author = author
    # self.price = price
    # self.publisher = publisher
    # self.pubdate = pubdate
    #
    # def seacher_book(self):
    # print("这本书的主题是:{}".format(self.title))
    # print("这本书的价格是:{}".format(self.price))
    # print("这本书的作者是:{}".format(self.author))
    # print("这本书的出本社是:{}".format(self.publisher))
    # print("这本书的出版时间是:{}".format(self.pubdate))
    #
    # if __name__ == '__main__':
    # book = Book("Selenium")
    # book.seacher_book()


    # #类的继承
    # #父类
    # class Book:
    # def __init__(self,title,author,price):
    # self.title = title
    # self.author = author
    # self.price = price
    #
    # def seacher_book(self):
    # print("这本书的主题是:{}".format(self.title))
    # print("这本书的作者是:{}".format(self.author))
    # print("这本书的价格是:{}".format(self.price))
    #
    # #子类
    # class ReadBook(Book):
    # def readbook(self):
    # print("该书正在读中...")
    #
    #
    # #实例化子类
    # book = ReadBook("Python经典","Tao","11.42")
    # book.seacher_book()
    # book.readbook()


    #类的重写
    #父类
    class Book:
    def __init__(self,title,author,price):
    self.title = title
    self.author = author
    self.price = price

    def seacher_book(self):
    print("这本书的主题是:{}".format(self.title))
    print("这本书的作者是:{}".format(self.author))
    print("这本书的价格是:{}".format(self.price))

    #子类
    class ReadBook(Book):
    #构造方法 --初始化方法 (放的是公共的东西)
    def __init__(self,title,author,price,publisher,pubdate):
    Book.__init__(self,title,author,price)
    self.publisher = publisher
    self.pubdate = pubdate

    def readbook(self):
    print("该书正在读中...")

    def seacher_book(self):
    print("这本书的主题是:{}".format(self.title))
    print("这本书的价格是:{}".format(self.price))
    print("这本书的作者是:{}".format(self.author))
    print("这本书的出本社是:{}".format(self.publisher))
    print("这本书的出版时间是:{}".format(self.pubdate))

    #实例化子类
    book = ReadBook("Python经典","Tao","11.42","清华大学出版社",datetime.datetime.now())
    book.readbook()
    book.seacher_book()
  • 相关阅读:
    WinPE U盘安装原版Win10系统详细教程
    Foxmail for windows 客户端设置和 IMAP、POP3/SMTP 的设置
    微信打开X5调试,使微信页面可以在谷歌浏览器调试
    古今时辰对照表--选择吉日吉时,养生时辰必看
    2020爱你爱你,新的一年,新的开始,2020我想对你说
    人民日报推荐好文《善待你所在的单位》
    致大学生,我把私藏多年的的实用工具/学习网站都贡献出来了~~
    使用poco 的NetSSL_OpenSSL 搭建https 服务端,使用C++客户端,java 客户端访问,python访问(python还没找到带证书访问的代码.)
    C++ activemq CMS 学习笔记.
    关于 Poco::TCPServer框架 (windows 下使用的是 select模型) 学习笔记.
  • 原文地址:https://www.cnblogs.com/Teachertao/p/11707851.html
Copyright © 2020-2023  润新知