博客
关于我
python类的学习
阅读量:330 次
发布时间:2019-03-04

本文共 796 字,大约阅读时间需要 2 分钟。

init
del
Class Cat:	def __init__(self,new_name):		self.name = new_name		printf("%s"%self.name)	def __del__(self):		printf("%s"%self.name)tom = Cat("Tom")print('-'*50)

子类必须在括号内指定父类的名称

9.3.4 重写父类的方法

与重写父类方法同名,python不会考虑这个父类方法

9.3.5 实例用作属性

class ElectricCar(Car):	def __init__:		self.battery = Battery()

9.4 导入类

python允许将类存储在某个模块中,然后在主程序中导入所需要的模块

"""一个可用于表示汽车的类""""""存储在car.py"""class Car():	def __init__(self,make,model,year):		self.make = male;		self.model = model;		self.year = year;		self.odometer_reading = 0;	def update_odometer(self,mileage):		if mileage>= self.odometer_reading:			self.odometer_reading = mileage;		else:			print("You can't roll back an odometer_reading")
from Car import Car

9.4.4 导入整个模块

使用module_name.class_name访问所需要的类

9.5 python标准库

from random import randitx = randit(1,6)

转载地址:http://nesh.baihongyu.com/

你可能感兴趣的文章
Mysql 数据库InnoDB存储引擎中主要组件的刷新清理条件:脏页、RedoLog重做日志、Insert Buffer或ChangeBuffer、Undo Log
查看>>
mysql 数据库备份及ibdata1的瘦身
查看>>
MySQL 数据库备份种类以及常用备份工具汇总
查看>>
mysql 数据库存储引擎怎么选择?快来看看性能测试吧
查看>>
MySQL 数据库操作指南:学习如何使用 Python 进行增删改查操作
查看>>
MySQL 数据库的高可用性分析
查看>>
Mysql 数据库重置ID排序
查看>>
Mysql 数据类型一日期
查看>>
MySQL 数据类型和属性
查看>>
Mysql 整形列的字节与存储范围
查看>>
MySQL 日期时间类型的选择
查看>>
MySQL 是如何加锁的?
查看>>
mysql 更新子表_mysql 在update中实现子查询的方式
查看>>
MySQL 有什么优点?
查看>>
mysql 权限整理记录
查看>>
mysql 权限登录问题:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
查看>>
MYSQL 查看最大连接数和修改最大连接数
查看>>
mysql 查看锁_阿里/美团/字节面试官必问的Mysql锁机制,你真的明白吗
查看>>
MySql 查询以逗号分隔的字符串的方法(正则)
查看>>
MySQL 查询优化:提速查询效率的13大秘籍(避免使用SELECT 、分页查询的优化、合理使用连接、子查询的优化)(上)
查看>>