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.,
【[Python] Use Python Classes】
#ball.pyclass 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 = pressuredef inflate(self, psi):
self.pressure = self.pressure + psidef 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笔记】使用python的pyquery简单爬取数据demo
- Python批量将ppt转换为pdf
- mysql视图简介与使用
- 爬虫程序部署后常见问题整理
- Python_计算机基础
- python 处理json
- 【python】python文件处理
- 【Python】Python数组
- Python 循环的本质就是一段代码懒得重复写