[Python] Use Python Classes
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 python学习——python环境配置
1 python学习--python环境配置 要学习python语言,光看书看教程还是不好,得动手去写.当然,不管学习什么编程语言,最佳的方式还在于实践. 要实践,先得有一个Python解释器来解释执 ...
- CentOS使用virtualenv搭建独立的Python环境-python虚拟环境
CentOS使用virtualenv搭建独立的Python环境-python虚拟环境 virtualenv可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解 ...
- Embeding Python & Extending Python with FFPython
Introduction ffpython is a C++ lib, which is to simplify tasks that embed Python and extend Python. ...
- python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案
python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案 importerror:no mo ...
- 翻译文章“AST 模块:用 Python 修改 Python 代码”---!!注意ironpathyon未实现此功能
https://github.com/upsuper/blog/commit/0214fdd084c4adf2de2ed9912d644fb59ce13a1c +Title: [翻译] AST 模块: ...
- Python学习(二) 运行Python,编译Python
无论windos还是Linux只要安装了python,配置好了环境变量,则在命令行输入python这个命令的时候就会进入交互模式.在这个模式下可以进行一些简单的python代码编写.退出可以使用exi ...
- Python:Python学习总结
Python:Python学习总结 背景 PHP的$和->让人输入的手疼(PHP确实非常简洁和强大,适合WEB编程),Ruby的#.@.@@也好不到哪里(OO人员最该学习的一门语言). Pyth ...
- Python 正则表达式 (python网络爬虫)
昨天 2018 年 01 月 31 日,农历腊月十五日.20:00 左右,152 年一遇的月全食.血月.蓝月将今晚呈现空中,虽然没有看到蓝月亮,血月.月全食也是勉强可以了,还是可以想像一下一瓶蓝月亮洗 ...
- Python和Python解释器
目录 Python介绍(了解) Python解释器发展史(了解) Python解释器(了解) CPython IPython PyPy Jython IronPython 安装Python解释器(掌握 ...
- Python之python的一些理解
应用领域: 1. 网络爬虫 2. 大数据分析与挖掘 3. 机器学习 4. web应用 5. 游戏开发 6. 自动化运维 入门学习网站: imooc,廖雪峰,黑马 环境变量 --- 就是告诉电脑,你的程 ...
随机推荐
- python批量下载色影无忌和蜂鸟的图片 爬虫小应用
有些冗余信息.由于之前測试正則表達式.所以没有把它们给移走.只是不影响使用. # -*- coding:utf-8 -*- import re,urllib,sys,os,time def getAl ...
- 8.解决IntelliJ Idea 集成TortoiseSVN 时找不到svn.exe
转自:https://blog.csdn.net/beibeijia125/article/details/70183533?utm_source=blogxgwz9 首先我们可以在http://su ...
- Filenames and paths
Files are organized into directories (also called ‘folders’). Every running program has a ‘current d ...
- 11.string容器
#include <iostream> //string的本质也是容器 #include <string> #include <cstdlib> using nam ...
- codeforces 527 C Glass Carving
Glass Carving time limit per test 2 seconds Leonid wants to become a glass carver (the person who cr ...
- ipad mini2 升级9.0.2后解锁白屏解决
解锁白屏是个什么现象?就是当你用手指滑动解锁后出现输入密码的界面后,1秒之内屏幕变白,中间一个黑色的苹果,几秒之后重新回到滑动解锁的界面.我出现这个现象不是因为升级了9.0.2,而是升级了9.0.2之 ...
- Input Team
The Chromium Input team (aka input-dev) is a web platform team focused on making touch (P1) and othe ...
- php八大设计模式之策略模式
策略模式提供一个虚拟的整体,根据不同的要求(参数)提供不同的"零件"(调用不同的"零件"实现不同的结果). <?php /** * 策略模式 * 跟工厂模 ...
- Unity 获得Android Context上下文
1.获取Context AndroidJavaObject context = new AndroidJavaClass ("com.unity3d.player.UnityPlayer&q ...
- eclipse 启动报错has value '1.7', but '1.8' is required
由于安装elasticsearch5.x版本时需要jdk8,所以在本机安装了,不过后来发现启动eclipse时报错: Error: Registry key 'Software\JavaSoft\Ja ...