python面向对象编程
2017-08-04 22:43
204 查看
花了一个下午把优达的的面向对象python课刷了,回去之前做个总结。
主要是两个例子
当child中的show_info没有定义,可以调用Parent的方法
主要是两个例子
1 电影预告网页
1.1 mian
import media import fresh_tomatoes toy_stort = media.Movie("Toy Story", "A story of a boy and his toys", "link", "link") # print(toy_stort.storyline) avatar = media.Movie("Avatar","A marinr on an alien plant", "Link","http://www.iqiyi.com/v_19rrn8vkts.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01"); # print(avatar.storyline) # avatar.show_traile() sanssans = media.Movie("Sanssans","A marinr on an alien plant", "Link","http://video.mtime.com/66932/?mid=225337") # sanssans.show_traile() moives = [toy_stort,avatar,sanssans] # fresh_tomatoes.open_movies_page(moives) # print(media.Movie.VALID_RATINGS) print(media.Movie.__doc__)
1.2 media
import webbrowser class Movie(): """ This class provides a way to store movie related information """ VALID_RATINGS = ["G","PG","PG-13","R"] def __init__(self,movie_title,movie_storyline,poster_image_url,trailer_url): self.title = movie_title self.storyline = movie_storyline self.poster_image_url = poster_image_url self.trailer_youtube_url = trailer_url def show_traile(self): webbrowser.open(self.trailer_youtube_url)
2 继承例子
child 初始化可以继承自Parent当child中的show_info没有定义,可以调用Parent的方法
class Parent(): def __init__(self, last_name, eye_color): print("Parent Constructor Called") self.last_name = last_name self.eye_color = eye_color def show_info(self): print("Last Name - "+self.last_name) print("Eye Color - "+self.eye_color) class child(Parent): def __init__(self, last_name, eye_color, number_of_toys): print("Child Constructor Called") Parent.__init__(self, last_name, eye_color) self.number_of_toys=number_of_toys def show_info(self): print("Last Name - "+self.last_name) print("Eye Color - "+self.eye_color) print("number_of_toys -"+self.number_of_toys) biily_cyrus = Parent("Cyrus","blue") print(biily_cyrus.last_name) biily_cyrus.show_info() # miley_cyrus = child("Cyrus","blue","2") print(miley_cyrus.last_name) print(miley_cyrus.number_of_toys) miley_cyrus.show_info()
相关文章推荐
- Python-面向对象编程
- Python面向对象编程
- Python(四)--面向对象编程
- Python学习笔记 6--高阶函数、面向对象编程
- Python 之 基础面向对象编程
- python第24篇之--类的初始化(面向对象编程)
- Python学习笔记 - 面向对象编程
- Python学习日志(六)之面向对象编程
- python 中面向对象编程简单总结1
- Python的面向对象编程
- Python3.5——面向对象编程
- 洗礼灵魂,修炼python(34)--面向对象编程(4)—继承
- 【python面向对象编程】
- python 面向对象编程
- python小菜的学习之路 之 面向对象编程
- Python面向对象编程
- 关于Python面向对象编程的知识点总结
- Python:面向对象编程
- 深入讲解Python中面向对象编程的相关知识
- Python面向对象编程总结(1)(转)