Day7 Python学习笔记&关键注意点

时间:2019-08-22
本文章向大家介绍Day7 Python学习笔记&关键注意点,主要包括Day7 Python学习笔记&关键注意点使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

 Part 1:Python学习笔记

===================

7.包与模块管理

7.1.模块

7.2.指令

7.2.1.import

 1 import math 
 2 import models 
 3 import views  
 4 
 5 print('hello')  
 6 
 7 def hello():     
 8 print(models.page)  
 9 hello()  
10 if __name__ == "__main__":     
11 views.test()

7.2.2.from

  • 示例1
1 import math 
2 from models import page  
3 print('hello')  
4 
5 def hello():     
6 print(page)  
7 
8 hello()
  • 示例2
1 import math  
2 from models import *      
3 print('hello')    
4 
5 def hello():      
6 test()    
7 
8 hello()
  • 示例3
1 from models import test as m_test  
2 from views import test as v_test  
3 
4 m_test() 
5 v_test()

7.2.3. import importlib; importlib.reload(模块)

7.3.包

7.3.1. __init__ 初始化文件

7.4.使用原因

7.4.1.代码重用

7.4.2.命名空间

7.4.3.实现数据或服务共享

7.5. 步骤

7.5.1. 找到模块文件

7.5.2. 编译为字节码

7.5.3. 运行模块文件

7.6.搜索范围

7.6.1. 当前程序主目录

7.6.2. 环境变量

7.6.3. 标准库

7.6.4. 第三方安装库-扩展库

8.面向对象编程

8.1.步骤

8.1.1.OOA 面向对象分析

  • 1. 分析对象-万物皆对象
  • 2. 类定义对象代码模板(模板)-将分析的对象变为代码
  • 3. 实例化(内存对象)

8.1.2.OOD 面向对象设计

8.1.3.OOP 面向对象编程

8.2.实现

8.2.1.1. 分析对象特征和行为

8.2.2.2. 写类描述模板对象

8.2.3.3. 实例化,模拟过程

8.3.案例1

 1 title = 'Python ru men'
 2 price = 39.00
 3 author = "Peter"
 4 
 5 def search_book(title):
 6     print('Search the book key words {} book'.format(title))
 7 
 8 
 9 book = {
10     'title':'Python rumen',
11     'price':39.00,
12     'author':'Peter',
13     'search_book':search_book
14 }
15 
16 print(book['title'])
17 print(book.get('price',0.0))
18 book.get('search_book')('Python')

8.3.案例2

 1 import datetime
 2 
 3 class Book:
 4     def __init__(self,title,price,author,publisher,pubdate):
 5         self.title = title
 6         self.price = price
 7         self.author = author
 8         self.publisher = publisher
 9         self.pubdate = pubdate
10 
11     def __repr__(self):
12         return '<Book {} at 0x{}>'.format(self.title,id(self))
13 
14     def print_info(self):
15         print('The book information is as follows:')
16         print('title:{}'.format(self.title))
17         print('price:{}'.format(self.price))
18         print('author:{}'.format(self.author))
19         print('publisher:{}'.format(self.publisher))
20         print('pubdate:{}'.format(self.pubdate))
21 
22 
23 book1 = Book('C#',29.9,'Tom','Youpinketang',datetime.date(2016,3,1))   #A real object
24 
25 book1.print_info()

Part 2:Python学习注意点

=====================

1. 第一步:分析对象

2. 第二步:写类

3. 第三部:实例化,创建对象

原文地址:https://www.cnblogs.com/hemin96/p/11393736.html