【坚持】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'
【坚持】Selenium+Python学习记录 DAY8的更多相关文章
- Python学习记录day8
目录 Python学习记录day8 1. 静态方法 2. 类方法 3. 属性方法 4. 类的特殊成员方法 4.1 __doc__表示类的描述信息 4.2 __module__ 和 __class__ ...
- 【坚持】Selenium+Python学习记录 DAY11
2018/06/1-2018/06/4 参考资料: [菜鸟教程](http://www.runoob.com/python3/python3-examples.html) [Python解惑:True ...
- 【坚持】Selenium+Python学习记录 DAY10
2018/05/31-2018/06/1 [官方文档](https://www.jetbrains.com/help/pycharm/set-up-a-git-repository.html) 通过p ...
- 【坚持】Selenium+Python学习记录 DAY9
2018/05/29 [来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html) 运算符重载 https://segmentfault ...
- Python学习记录day6
title: Python学习记录day6 tags: python author: Chinge Yang date: 2016-12-03 --- Python学习记录day6 @(学习)[pyt ...
- Python学习记录day5
title: Python学习记录day5 tags: python author: Chinge Yang date: 2016-11-26 --- 1.多层装饰器 多层装饰器的原理是,装饰器装饰函 ...
- Python学习记录day7
目录 Python学习记录day7 1. 面向过程 VS 面向对象 编程范式 2. 面向对象特性 3. 类的定义.构造函数和公有属性 4. 类的析构函数 5. 类的继承 6. 经典类vs新式类 7. ...
- Python学习记录:括号配对检测问题
Python学习记录:括号配对检测问题 一.问题描述 在练习Python程序题的时候,我遇到了括号配对检测问题. 问题描述:提示用户输入一行字符串,其中可能包括小括号 (),请检查小括号是否配对正确, ...
- 【坚持】Selenium+Python学习之从读懂代码开始 DAY1
学习Selenium+Python已经好几个月了,但越学发现不懂的东西越多. 感觉最大的问题还是在于基础不扎实,决定从头开始,每天坚持读代码,写代码. 相信量变一定能到质变!!! 2018/05/09 ...
随机推荐
- 使用js插件进行设备检测
一.分析新浪网是怎么做的 如新浪网有两种版本,一种是pc版,存放在www.sina.com.cn这个服务器上:另外一种是手机版,存放在www.sina.cn这个服务器上 原理是当用户输入网址www ...
- linux_bc命令
bc 命令: bc 命令是用于命令行计算器. 它类似基本的计算器. 使用这个计算器可以做基本的数学运算. 语法: 语法是 bc [命令开关]命令开关: -c 仅通过编译. ...
- 最简单的方式在linux上升级node.js版本
node的升级频率太高,n模块来升级是最方便的,网上看了很多资料介绍使用n模块,但是安装n模块之后却经常找不到这个命令 很多同学安装之后直接去使用n会发现命令不存在,就停留在这一步无法前进了. 解决 ...
- etcd 删除
vim /etc/sysconfig/flanneld FLANNEL_ETCD_ENDPOINTS="https://192.168.30.241:2379,https://192.168 ...
- virtualbox+vagrant学习-3-Vagrant Share-1-简介
Vagrant Share 通过 ngrok 内网穿透功能实现让全世界人可以访问虚拟机的服务 Vagrant Share允许你与世界上的任何人共享您的Vagrant环境,几乎支持你在任何网络环境中使用 ...
- python 编码规范起源:PEP8 编码规范中文版
PEP: 8 标题: Python代码的样式指南 版: c451868df657 最后修改: 2016-06-08 10:43:53 -0400(2016年6月8日星期三) 作者: Guido van ...
- Kafka设计解析(十八)Kafka与Flink集成
转载自 huxihx,原文链接 Kafka与Flink集成 Apache Flink是新一代的分布式流式数据处理框架,它统一的处理引擎既可以处理批数据(batch data)也可以处理流式数据(str ...
- 【题解】洛谷P1169 [ZJOI2007] 棋盘制作(坐标DP+悬线法)
次元传送门:洛谷P1169 思路 浙江省选果然不一般 用到一个从来没有听过的算法 悬线法: 所谓悬线法 就是用一条线(长度任意)在矩阵中判断这条线能到达的最左边和最右边及这条线的长度 即可得到这个矩阵 ...
- centos7下部署iptables环境纪录(关闭默认的firewalle)(转)
下面介绍centos7关闭firewall安装iptables,并且开启80端口.3306端口的操作记录:[root@localhost ~]# cat /etc/redhat-release Cen ...
- K2 BPM介绍(1)
K2 BPM介绍(1) 官网访问地址: 中文官网 英文官网 它是一个强大的BPM产品 K2 BPM详解 产品特性 与任何内容集成 Integrate with Anything 功能丰富的窗体 Fea ...