【坚持】Selenium+Python学习记录 DAY8

2018/05/ 28

[来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html

继续敲类相关的代码

#No.1
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))

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.py
ken 说:我 10 岁了,我在读 3 年纪
#No.2
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))

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.3
class 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.4
class 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.py
1
2
2
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    print(counter.__secretCount)
AttributeError: ‘JustCounter‘ object has no attribute ‘__secretCount‘
#No.5
class 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.py
name :  菜鸟教程
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‘

原文地址:https://www.cnblogs.com/flyin9/p/9102710.html

时间: 2024-08-04 04:57:09

【坚持】Selenium+Python学习记录 DAY8的相关文章

Python学习记录day6

Python学习记录day6 学习 python Python学习记录day6 1.反射 2.常用模块 2.1 sys 2.2 os 2.3 hashlib 2.3 re 1.反射 反射:利用字符串的形式去对象(默认)中操作(寻找)成员 cat commons.py #!/usr/bin/env python#_*_coding:utf-8_*_''' * Created on 2016/12/3 21:54. * @author: Chinge_Yang.''' def login(): pr

Python学习记录day1

Python学习记录博客是本人记录学习python3过程中的一些记录和过程,日后也可以帮助自己温习. python优点: 1.Python入门简单,功能强大,适用性强: 2.开发效率高,第三方库强大且多: 3.Python无需考虑底层细节: 4.可移植性,跨平台: 5.可扩展性: 6.可嵌入性,Pthon可嵌入到C/C++程序中: python缺点: 1.速度慢,Python比C慢很多,比java也慢一点: 2.代码不能加密,源码是明文: 3.线程不能利用多 CPU 问题: python版本2和

Python学习记录day3

Python学习记录 day3 今天是银角大王武sir讲课.先回顾了上节课所学,然后讲到了面向对象思想. set set是一个无序且不重复,可嵌套的元素集合 class set(object):     """     set() -> new empty set object     set(iterable) -> new set object     Build an unordered collection of unique elements.     

python学习记录第五篇--遍历目录

#coding=utf-8'''@author: 简单遍历目录删除文件的小程序'''import os#查找文件操作def findFile(path): fileList=[] for rootPath,subRoot,fileName in os.walk(path): for sub in fileName: if os.path.isfile(os.path.join(rootPath,sub)): k=os.path.splitext(sub)[1].lower() if k in (

python学习记录第四篇--数据库

只要用到MySQLdb,使用时请先安装MySQLdb,百度上可以下载! #coding=utf-8'''@author: 使用python操作MySQL数据库'''import MySQLdb#import MySQLdb.cursorsconn=MySQLdb.connect(user='root',passwd='root') #connect共三个值,user,passwd,host,无密码且连接本地数据库时,可以都为空.cur=conn.cursor() #创建游标,使用游标进行数据库操

Python学习记录day5

title: Python学习记录day5 tags: python author: Chinge Yang date: 2016-11-26 1.多层装饰器 多层装饰器的原理是装饰器装饰函数后其实也是一个函数这样又可以被装饰器装饰. 编译是从下至上进行的执行时是从上至下进行. #!/usr/bin/env python # _*_coding:utf-8_*_ ''' * Created on 2016/11/29 20:38. * @author: Chinge_Yang. ''' USER

Python学习记录-socket编程

Python学习记录-socket编程 学习 python socket Python学习记录-socket编程 1. OSI七层模型详解 2. Python socket 3. socket()函数 4. TCP socket通信流程 5. Python Internet 模块 1. OSI七层模型详解 以上图见:http://blog.csdn.net/yaopeng_2005/article/details/7064869 其它详情可参考:socket网络基础 2. Python sock

Python学习记录-2016-12-17

今日学习记录 模块: import os#导入os模块 import sys#导入sys模块 os.system("df -h")#执行df -h命令 cmd_res = os.popen("df -h").read()#将命令的返回结果赋值给cmd_res,如果不加入.read()会显示命令的返回加过在内存的位置 print(sys.path)#显示系统变量路径,一般个人模块位于site-packages下,系统模块位于lib下 print(sys.argu[2]

Python学习记录-2016-11-29

今日学习记录: 心灵鸡汤: 要有合适自己的目标,一个目标一个目标实现,切忌好高骛远: 最好的投资就是投资自己: 实现梦想 学习,学习,再学习: Talk is cheap. 从本身而言,余三十而立之年,从事测试行业7七年有余,一年半华为外包路由器,两年无线wifi测试,一年半网管软件测试,一年自动化测试经理,推行公司自动化测试进程,从开始的TCL,到现在的python,工欲善其事必先利其器,所以自己来学习,总体我认为我的目标是一直前进的,不断变化的,但是方向并没有大的错误,有些累,所以近期有些懈