【堅持】Selenium+Python學習記錄 DAY8

來源:互聯網
上載者:User

標籤:lin   tee   pytho   method   sel   來源   www   test   cti   

2018/05/ 28

[來源:菜鳥教程](http://www.runoob.com/python3/python3-examples.html)

繼續敲類相關的代碼
#No.1class people:    name = ‘‘    age = 0    __weight = 0    def __init__(self, n, a, w):        self.name = n        self.age = a        self.__weight = w    def speak(self):        print("%s 說:我 %d 歲。" %(self.name, self.age))class student(people):    grade = ‘‘    def __init__(self, n, a, w, g):        people.__init__(self, n, a, w)        self.grade = g    def speak(self):        print("%s 說:我 %d 歲了,我在讀 %d 年紀" %(self.name, self.age, self.grade))s = student(‘ken‘, 10, 60, 3)s.speak()
resut:d:\fly\Python (master -> origin)λ python test.pyken 說:我 10 歲了,我在讀 3 年紀
#No.2class people:    name = ‘‘    age = 0    __weight = 0    def __init__(self, n, a, w):        self.name = n        self.age = a        self.__weight = w    def speak(self):        print("%s 說:我 %d 歲。" %(self.name, self.age))class student(people):    grade = ‘‘    def __init__(self, n, a, w, g):        people.__init__(self, n, a, w)        self.grade = g    def speak(self):        print("%s 說: 我 %d 歲了,我在讀 %d 年級"%(self.name, self.age, self.grade))class speaker():    topic = ‘‘    name = ‘‘    def __init__(self, n, t):        self.name = n        self.topic = t    def speak(self):        print("我叫 %s, 我是一個演說家, 我演講的主題是 %s" %(self.name, self.topic))class sample(speaker, student):    a = ‘‘    def __init__(self, n, a, w, g, t):        student.__init__(self, n, a, w, g)        speaker.__init__(self, n, t)test = sample("Tim", 25, 80, 4, "Python")test.speak()
resut:d:\fly\Python (master -> origin)λ python test.py我叫 Tim, 我是一個演說家, 我演講的主題是 Python
#No.3class parent:    def myMethod(self):        print(‘調用父類方法‘)class child(parent):    def myMethod(self):        print(‘調用子類方法‘)c = child()c.myMethod()super(child, c).myMethod()
resut:d:\fly\Python (master -> origin)λ python test.py調用子類方法調用父類方法
#No.4class JustCounter:    __secretCount = 0    publicCount = 0    def count(self):        self.__secretCount += 1        self.publicCount += 1        print(self.__secretCount)counter = JustCounter()counter.count()counter.count()print(counter.publicCount)print(counter.__secretCount)
resut:d:\fly\Python (master -> origin)λ python test.py122Traceback (most recent call last):  File "test.py", line 14, in <module>    print(counter.__secretCount)AttributeError: ‘JustCounter‘ object has no attribute ‘__secretCount‘
#No.5class Site:    def __init__(self, name, url):        self.name = name        self.__url = url    def who(self):        print(‘name : ‘, self.name)        print(‘url : ‘, self.__url)    def __foo(self):        print("這是私人方法")    def foo(self):        print(‘這是公用方法‘)        self.__foo()x = Site(‘菜鳥教程‘, ‘www.runoob.com‘)x.who()x.foo()x.__foo()
resut:d:\fly\Python (master -> origin)λ python test.pyname :  菜鳥教程url :  www.runoob.com這是公用方法這是私人方法Traceback (most recent call last):  File "test.py", line 20, in <module>    x.__foo()AttributeError: ‘Site‘ object has no attribute ‘__foo‘

【堅持】Selenium+Python學習記錄 DAY8

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.