【坚持】Selenium+Python学习之从读懂代码开始 DAY7

2018/05/25

EC

[EC](https://github.com/easonhan007/webdriver_guide/blob/master/34/expected_conditions.py.md
[@classmethod](http://www.runoob.com/python/python-func-classmethod.html
[Source code for selenium.webdriver.support.expected_conditions](https://seleniumhq.github.io/selenium/docs/api/py/_modules/selenium/webdriver/support/expected_conditions.html#visibility_of_all_elements_located
[菜鸟教程](http://www.runoob.com/python3/python3-examples.html

学习过程中涉及到的知识点:@classmethod

#No.1
class A(object):
    bar = 1
    def func1(self):
        print('foo')

    @classmethod
    def func2(cls):
        print('func2')
        print(cls.bar)
        cls().func1()

A.func2()
resut:
C:\Users\Superpj\PycharmProjects\selenium_python\venv\Scripts\python.exe D:/fly/Python/test.py
func2
1
foo

关于类相关的内容还是有点晕,把相关的代码再敲一遍!

#No.2
class MyClass:
    i = 123456
    def f(self):
        return 'hello world'

x = MyClass()

print("MyClass 类的属性i 为 ", x.i)
print("MyClass 类的方法f输出为:", x.f())
resut:
C:\Users\Superpj\PycharmProjects\selenium_python\venv\Scripts\python.exe D:/fly/Python/test.py
MyClass 类的属性i 为  123456
MyClass 类的方法f输出为: hello world
#No.3
class Complex:
    def __init__(self, realpart, imagpart):
        self.r = realpart
        self.i = imagpart

x = Complex(3.0, -4.5)
print(x.r, x.i)
resut:
C:\Users\Superpj\PycharmProjects\selenium_python\venv\Scripts\python.exe D:/fly/Python/test.py
3.0 -4.5
#No.4
class Test:
    def prt(self):
        print(self)
        print(self.__class__)

t = Test()
t.prt()
resut:
C:\Users\Superpj\PycharmProjects\selenium_python\venv\Scripts\python.exe D:/fly/Python/test.py
<__main__.Test object at 0x000001CFFFAEF908>
<class '__main__.Test'>
#No.5
class 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))

p = people('runoob', 10, 30)
p.speak()
resut:
C:\Users\Superpj\PycharmProjects\selenium_python\venv\Scripts\python.exe D:/fly/Python/test.py
runoob 说: 我 10

猜你喜欢

转载自www.cnblogs.com/flyin9/p/9088633.html