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的更多相关文章

  1. Python学习记录day8

    目录 Python学习记录day8 1. 静态方法 2. 类方法 3. 属性方法 4. 类的特殊成员方法 4.1 __doc__表示类的描述信息 4.2 __module__ 和 __class__ ...

  2. 【坚持】Selenium+Python学习记录 DAY11

    2018/06/1-2018/06/4 参考资料: [菜鸟教程](http://www.runoob.com/python3/python3-examples.html) [Python解惑:True ...

  3. 【坚持】Selenium+Python学习记录 DAY10

    2018/05/31-2018/06/1 [官方文档](https://www.jetbrains.com/help/pycharm/set-up-a-git-repository.html) 通过p ...

  4. 【坚持】Selenium+Python学习记录 DAY9

    2018/05/29 [来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html) 运算符重载 https://segmentfault ...

  5. Python学习记录day6

    title: Python学习记录day6 tags: python author: Chinge Yang date: 2016-12-03 --- Python学习记录day6 @(学习)[pyt ...

  6. Python学习记录day5

    title: Python学习记录day5 tags: python author: Chinge Yang date: 2016-11-26 --- 1.多层装饰器 多层装饰器的原理是,装饰器装饰函 ...

  7. Python学习记录day7

    目录 Python学习记录day7 1. 面向过程 VS 面向对象 编程范式 2. 面向对象特性 3. 类的定义.构造函数和公有属性 4. 类的析构函数 5. 类的继承 6. 经典类vs新式类 7. ...

  8. Python学习记录:括号配对检测问题

    Python学习记录:括号配对检测问题 一.问题描述 在练习Python程序题的时候,我遇到了括号配对检测问题. 问题描述:提示用户输入一行字符串,其中可能包括小括号 (),请检查小括号是否配对正确, ...

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

    学习Selenium+Python已经好几个月了,但越学发现不懂的东西越多. 感觉最大的问题还是在于基础不扎实,决定从头开始,每天坚持读代码,写代码. 相信量变一定能到质变!!! 2018/05/09 ...

随机推荐

  1. 将jpg压缩成webp格式的图片

    cwebp名称 cwebp -压缩图像文件为的WebP文件概要 cwebp [选项] INPUT_FILE -o output_file.webp描述 cwebp压缩使用的WebP格式的图像.输入格式 ...

  2. ubuntu18.04 mariadb start失败

    在Ubuntu 安装mariadb 再restart 后出现错误 journalctl -xe 发现 apparmor权限问题 AppArmor 是一款与SeLinux类似的安全框架/工具,其主要作用 ...

  3. c++问题整理

    1.C++ 多态,多态的实现,c++虚函数,虚函数和纯虚函数有什么区别,虚函数的实现原理,虚继承,析构函数能否为虚,为什么析构要虚函数,析构函数声明为虚函数的作用,构造函数为啥不能定义为虚函数,析构函 ...

  4. (转)Fiddler菜单栏详解

    原文作者:子信风蓝蓝 传送门:http://www.cnblogs.com/chengchengla1990/p/5681775.html Statistics 页签 完整页签如下图: Statist ...

  5. P1880 [NOI1995]石子合并

    题目描述 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计算出将N堆石子合并成1 ...

  6. UCOSii和Linux的区别和联系

    UCOSii和Linux的区别和联系 想通过UCOSii来理解Linux的系统架构,故参考一些资料,简单整理了一下UCOSii和Linux的区别和联系,以此来更好的学习Linux. 其具体对比如下: ...

  7. CentOS 6.5环境下配置Arcgis Server 10.3

    感觉arcgis server在Windows系统下过于消耗资源,现将其配置到linux下,仅用于学习用.文中安装截图较多.因水平有限,难免有不周之处,请指教. 一.安装前准备 配置linux环境:此 ...

  8. MapReduce -- 统计天气信息

    示例 数据: -- :: 34c -- :: 36c -- :: 32c -- :: 37c -- :: 23c -- :: 45c -- :: 50c -- :: 33c -- :: 41c -- ...

  9. 填移动端坑系列一——如何让h5页面完美整屏显示

    原创哟,转载请附上本文连接(http://www.cnblogs.com/AliceX-J/p/6707908.html),作者 印前 后续更简单 前言: 最近让做一个h5的活动专题,便让我浩浩荡荡进 ...

  10. JS form跳转到新标签页并用post传参

    通过js实现跳转到一个新的标签页,并且传递参数.(使用post传参方式) 1 超链接<a>标签  (get传参)  <a href="http://www.cnblogs. ...