OOP object-oriented basis of python

# Class (object-oriented) the PageObject design pattern unittest knowledge 

# functional programming
Import datetime
book_info = {
"title": "the Python",
". Price": "33.1",
"auther": "moto",
"Publisher": " Peking University ",
" pubDate ": datetime.datetime.today ()
}

DEF seacher_book (book):
Print (" the book's theme is:. "format (book_info {} [" title "]))
Print (" it the price of the book is:. "format (book_info {} [". price "]))
Print (" author of this book is:. "format (book_info {} [" auther "]))
Print (" book Society is out:. "the format (book_info.get (" {} Publisher ")))
Print (" time of publication of this book: ". format (book_info.get (" {} pubdate ")))
#
# IF the __name__ == '__main__':
# seacher_book (book_info)

# constructor
# 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
PubDate self.pubdate = #
#
# DEF seacher_book (Self):
# Print ( "The book's theme is: {}." Format (self.title))
# Print ( "price of the book is: {}" .format (self.price))
# Print ( "author of this book is: {}." format (self.author))
# Print ( "book of the Society are: {}". format (self . Publisher))
# Print ( "time of publication of this book: {}." the format (self.pubdate))
#
# IF the __name__ == '__main__':
# = book book ( "the Selenium", 'Teacher', " 43.33 "," "()) , datetime.datetime.today Tsinghua
# book.seacher_book ()

written # default value of
# class Book:
# DEF __init __ (Self,
# title =" Appium test ",
# = author"",
# price = 0.0,
None Publisher = #,
# = pubDate datetime.datetime.now ()):
# = self.title title
# self.author author =
# = self.price. Price
# self.publisher Publisher =
# = pubDate self.pubdate
#
# DEF seacher_book (Self):
# Print ( "the book's theme is: {}." format (self.title))
# Print ( "price of the book is: {}." format (self.price))
# print ( "author of this book is: {}." format (self.author))
# print ( "book of the Society is: {}." format (self.publisher))
# print ( "this published book is: {} "the format (self.pubdate)).
#
# IF the __name__ == '__main__':
# = book book (" the Selenium ")
# book.seacher_book()


# # Class inheritance
## parent class
# class Book:
# DEF __init __ (Self, title, author,. Price):
# self.title title =
# = author self.author
# self.price. Price =
#
# DEF seacher_book (Self ):
# Print ( "the book's theme is: {}." format (self.title))
# Print ( "author of this book is: {}." format (self.author))
# Print ( " price of the book is: {}. "format (self.price))
#
# # subclasses
# class ReadBook (book):
# DEF ReadBook (Self):
# Print (" the book is read in ... " )
#
#
# # instantiable subclass
# book = ReadBook ( "Python classic", "Tao", "11.42")
# book.seacher_book ()
# Book.ReadBook ()


# class rewrite
# the parent
class Book:
__init __ DEF (Self, title, author,. price):
self.title = title
self.author = author
self.price. price =

DEF seacher_book (Self):
Print ( "The book's theme is: {}". format (self .title))
Print ( "author of this book is: {}." format (self.author))
Print ( "price of the book is: {}." format (self.price))

# subclass of
class ReadBook (Book):
# constructor - initialize method (put the public thing)
DEF __init __ (Self, title, author,. price, Publisher, pubDate):
Book .__ the init __ (Self, title, author,. price)
Self. Publisher = Publisher
self.pubdate = pubDate

DEF ReadBook (Self):
Print ( "the book is read in ...")

DEF seacher_book (Self):
print ( "The book's theme is: {}." format (self.title))
print ( "price of the book is: {}." format (self.price))
print ( "author of the book is: {}. "the format (self.author))
Print (" Society book that is: {}. "the format (self.publisher))
Print (" time of publication of this book: {}. " format (self.pubdate))

# instantiable subclass
book = ReadBook ( "Python classic", "Tao", "11.42 ", " Tsinghua University Press", datetime.datetime.now ())
book.readbook ()
Book .seacher_book ()

Guess you like

Origin www.cnblogs.com/Teachertao/p/11707851.html