Object oriented classes work much like classes in other languages. Learn how to create them and use them, learn the difference between class variables and instance variables, creating class methods, and learn how to create classes that inherit from other classes.,

#ball.py

class Ball:
def __init__(self, radius, color, weight):
self.radius = radius
self.color = color
self.weight = weight """
from ball import Ball
b = Ball(22, 'red', 10)
""" class Football:
"""A standard, regulation NFL ball"""
def __init__(self, diameter, color, pressure):
self.diameter = diameter
self.color = color
self.pressure = pressure def inflate(self, psi):
self.pressure = self.pressure + psi def deflate(self, psi):
self.pressure = self.pressure - psi # inherit Football
class PatriotsBall(Football):
def inflate(self, psi):
""" overwrite default method """
self.pressure = self.pressure - psi """
from ball import PatriotsBall
pb = PatriotsBall(22, 'blue', 10)
"""

[Python] Use Python Classes的更多相关文章

  1. 1 python学习——python环境配置

    1 python学习--python环境配置 要学习python语言,光看书看教程还是不好,得动手去写.当然,不管学习什么编程语言,最佳的方式还在于实践. 要实践,先得有一个Python解释器来解释执 ...

  2. CentOS使用virtualenv搭建独立的Python环境-python虚拟环境

    CentOS使用virtualenv搭建独立的Python环境-python虚拟环境 virtualenv可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解 ...

  3. Embeding Python & Extending Python with FFPython

    Introduction ffpython is a C++ lib, which is to simplify tasks that embed Python and extend Python. ...

  4. python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案

    python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案 importerror:no mo ...

  5. 翻译文章“AST 模块:用 Python 修改 Python 代码”---!!注意ironpathyon未实现此功能

    https://github.com/upsuper/blog/commit/0214fdd084c4adf2de2ed9912d644fb59ce13a1c +Title: [翻译] AST 模块: ...

  6. Python学习(二) 运行Python,编译Python

    无论windos还是Linux只要安装了python,配置好了环境变量,则在命令行输入python这个命令的时候就会进入交互模式.在这个模式下可以进行一些简单的python代码编写.退出可以使用exi ...

  7. Python:Python学习总结

    Python:Python学习总结 背景 PHP的$和->让人输入的手疼(PHP确实非常简洁和强大,适合WEB编程),Ruby的#.@.@@也好不到哪里(OO人员最该学习的一门语言). Pyth ...

  8. Python 正则表达式 (python网络爬虫)

    昨天 2018 年 01 月 31 日,农历腊月十五日.20:00 左右,152 年一遇的月全食.血月.蓝月将今晚呈现空中,虽然没有看到蓝月亮,血月.月全食也是勉强可以了,还是可以想像一下一瓶蓝月亮洗 ...

  9. Python和Python解释器

    目录 Python介绍(了解) Python解释器发展史(了解) Python解释器(了解) CPython IPython PyPy Jython IronPython 安装Python解释器(掌握 ...

  10. Python之python的一些理解

    应用领域: 1. 网络爬虫 2. 大数据分析与挖掘 3. 机器学习 4. web应用 5. 游戏开发 6. 自动化运维 入门学习网站: imooc,廖雪峰,黑马 环境变量 --- 就是告诉电脑,你的程 ...

随机推荐

  1. 14.mocha+should.js

    转自http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html 众所周知对于任何一个项目来说,做好单元测试都是必不 ...

  2. 登录那些事儿+ Session原理

    http://cnodejs.org/topic/5671441a1d2912ce2a35aaa1  登录那些事儿 http://www.jianshu.com/p/2b7c10291aad Sess ...

  3. Mysql锁表

    lock tables是线程锁定表 lock tables table_name read lock tables table_name write read表示 所有用户只能读取被锁的表,不能对其进 ...

  4. Android5.0之后的页面切换动画

    Android5.0之后给我们开发者剩了好多的事情,为什么这么说呢?还记得刚开始的时候,Android里面的所有的动画都要我们开发者自己来写,现在不需要了,因为5.0之后自带了好多的动画,比如:按钮点 ...

  5. 虚拟主机TOMCAT配置

    在tomcat中添加虚拟主机: 编辑"tomcat\conf\server.xml",在"<Engine></Engine>"元素中新加 ...

  6. PostgreSQL Replication之第九章 与pgpool一起工作(4)

    9.4 设置复制和负载均衡 要配置pgpool,我们可以简单地使用一个包含一种典型的配置信息的已经存在的样本文件,将它拷贝到我们的配置目录并修改之: $ cp /usr/local/etc/pgpoo ...

  7. Rain and Umbrellas(dp)

    题目链接 http://codeforces.com/problemset/problem/988/F 令dp[i][j]为走到目标为i处,手里拿着第j把伞,同时注意,在某处可能存在不止一把伞 #in ...

  8. UI Framework-1: Aura Layout Managers

    Layout Managers LayoutManager is a convenient abstraction that separates messy layout heuristics fro ...

  9. Xshell查看日志的基础使用

    2018\11\26 下载安装不多说,官网免费版即可,附上链接:https://www.netsarang.com/products/xsh_overview.html 打开后新建连接,输入主机ip即 ...

  10. wall---向系统当前所有打开的终端上输出信息

    wall命令用于向系统当前所有打开的终端上输出信息.通过wall命令可将信息发送给每位同意接收公众信息的终端机用户,若不给予其信息内容,则wall命令会从标准输入设备读取数据,然后再把所得到的数据传送 ...