7.包与模块管理及面向对象编程OPP1

包与模块管理

模块

指令

import
from
importlib.reload(模块)

__init__

why

代码重用
命名空间
实现数据或服务共享

步骤

1.找到模块文件
2.编译为字节码
3.运行模块文件

搜索范围

1.程序主目录
2.环境变量
3.标准库
4.扩展库

面向对象

步骤

OOA面向对象分析

OOD面向对象设计

OOP面向对象编程

1. 分析对象
2. 类定义对象代码模板(蓝图)
3. 实例化(内存对象)

实现

1.分析对象的特征行

2.写类描述对象模板

3.实例化,模拟

import datetime

class Book:
	def __init__(self,title,price,author,publisher,pubdate):
		self.title = title
		self.price = price
		self.author = author
		self.publisher = publisher
		self.pubdate = pubdate
	
	def print_info(self):
		print('当前这本书的信息如下:')
		print('标题:{}'.format(self.title))
		print('定价:{}'.format(self.price))
		print('作者:{}'.format(self.author))
		print('出版社:{}'.format(self.publisher))
		print('出版时间:{}'.format(self.pubdate))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值