-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorepython-reading-notes-how-day5.html
193 lines (147 loc) · 8.29 KB
/
corepython-reading-notes-how-day5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="index, follow" />
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,400;0,700;1,400&family=Source+Sans+Pro:ital,wght@0,300;0,400;0,700;1,400&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/stylesheet/style.min.css">
<link id="pygments-light-theme" rel="stylesheet" type="text/css"
href="https://blog.tonychow.me/theme/pygments/colorful.min.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/fontawesome.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/brands.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/solid.css">
<link href="https://blog.tonychow.me/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Tonychow's Blog Atom">
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#333333">
<!-- Windows Phone -->
<meta name="msapplication-navbutton-color" content="#333333">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- Microsoft EDGE -->
<meta name="msapplication-TileColor" content="#333333">
<meta name="author" content="tonychow" />
<meta name="description" content="" />
<meta name="keywords" content="corepython, reading-notes, python">
<meta property="og:site_name" content="Tonychow's Blog"/>
<meta property="og:title" content="Python 核心编程读书笔记 Day5"/>
<meta property="og:description" content=""/>
<meta property="og:locale" content="en_US"/>
<meta property="og:url" content="https://blog.tonychow.me/corepython-reading-notes-how-day5.html"/>
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="2014-07-16 00:00:00+08:00"/>
<meta property="article:modified_time" content=""/>
<meta property="article:author" content="https://blog.tonychow.me/author/tonychow.html">
<meta property="article:section" content="readings"/>
<meta property="article:tag" content="corepython"/>
<meta property="article:tag" content="reading-notes"/>
<meta property="article:tag" content="python"/>
<meta property="og:image" content="/images/avatar.jpg">
<title>Tonychow's Blog – Python 核心编程读书笔记 Day5</title>
</head>
<body class="light-theme">
<aside>
<div>
<a href="https://blog.tonychow.me/">
<img src="/images/avatar.jpg" alt="" title="">
</a>
<h1>
<a href="https://blog.tonychow.me/"></a>
</h1>
<p>Go/Python backend developer</p>
<ul class="social">
<li>
<a class="sc-github" href="https://github.com/chow1937" target="_blank">
<i class="fab fa-github"></i>
</a>
</li>
</ul>
</div>
</aside>
<main>
<nav>
<a href="https://blog.tonychow.me/">Home</a>
<a href="/archives.html">Archives</a>
<a href="/categories.html">Categories</a>
<a href="/tags.html">Tags</a>
<a href="https://blog.tonychow.me/feeds/all.atom.xml">Atom</a>
</nav>
<article class="single">
<header>
<h1 id="corepython-reading-notes-how-day5">Python 核心编程读书笔记 Day5</h1>
<p>
Posted on 三 16 七月 2014 in <a href="https://blog.tonychow.me/category/readings.html">readings</a>
• 1 min read
</p>
</header>
<div>
<p>今天的内容是 Python 中的面向对象和 Python 的执行环境。Python 支持 OOP,虽然很多情况下 Python 直接写函数就可
可以解决大部分的问题,但是 OOP 也是 Python 中的一个重要内容。下面继续总结笔记。</p>
<h3>第十三章:面向对象编程</h3>
<p>本章的内容是 Python 的面向对象编程,具体来说,讲述了 Python 中关于类和 OOP 的具体内容,包括继承,类的方法等
内容,同时也涉及了 Python 中的特殊方法等类的内容。下面是要点:</p>
<p>1.Python 中的实例方法都存在着第一个参数为 self 指示这个实例本身;</p>
<p>2.Python 中的类方法存在着第一个参数为 cls 通常指示这个类本身;</p>
<p>3.Python 中的 <code>__new__(cls,...)</code> 方法才是构建实例的方法,<code>__init__(self,...)</code> 方法是初始化实例的方法;</p>
<p>4.Python 中的子类的构造方法会覆盖父类的构造方法,子类不存在构造方法才会调用父类的构造方法;</p>
<p>5.Python 不支持纯虚函数或者抽象方法;</p>
<p>6.类属性绑定到类的 <code>__dict__</code> 中,实例属性绑定到实例的 <code>__dict__</code> 中;</p>
<p>7.如果实例中不存在一个和类属性同名的实例属性,则通过实例访问到的是类的属性,如果进行修改,则会在实例中保存
一个同名的实例属性存放在实例的 <code>__dict__</code> 中,这个实例属性会屏蔽同名的类属性,注意是屏蔽不是覆盖;</p>
<p>8.<code>__del__</code> 是实例的析构方法,只有在真正需要对该实例进行释放内存的时候才会调用,在 Python 中也就是意味着该
实例的引用计数为 0,进行垃圾回收操作;</p>
<p>9.类方法和实例方法也是普通的函数,和普通函数不同的是,类方法绑定了类,实例方法绑定了该实例,可以通过类调用
实例方法,但是此时实例方法没有被绑定,需要显式地传入一个实例作为第一个参数;</p>
<p>10.静态方法是在类范围内的普通函数,不是绑定的方法,静态方法也可以通过类继承的方式由子类继承;</p>
<p>11.类的父类保存在 <code>__bases__</code> 类属性中;</p>
<p>12.可以通过 <code>super(Cls, instance).method()</code> 的方式调用父类中的方法;</p>
<p>13.Old-style 类的 MRO 顺序是深度优先地搜索,直到找到,New-style 类的 MRO 顺序是广度优先搜索;</p>
<p>14.可以通过 <code>hasattr</code>,<code>getattr</code>,<code>setattr</code> 和 <code>delattr</code> 等内置函数对类和实例的属性进行操作;</p>
<p>15.Python 中的属性都是公开的,但是以下划线开始的属性会被混淆修改成为另外一个名称,显示出私有的属性;</p>
<p>16.字典会占用大量的内存,New-style 类可以通过 <code>__slots__</code> 属性存放实例属性,节省内存;</p>
<p>17.New-style 的类支持 <code>__getattribute__</code> 方法,实现了这个方法的类在属性被查找的时候都会调用这个方法;</p>
<p>18.描述符是一种将实现了 <code>__get__</code>,<code>__set__</code>,<code>__delete__</code> 特殊方法的类的实例作为另外一个类的类属性的对象
;</p>
</div>
<div class="tag-cloud">
<p>
<a href="https://blog.tonychow.me/tag/corepython.html">corepython</a>
<a href="https://blog.tonychow.me/tag/reading-notes.html">reading-notes</a>
<a href="https://blog.tonychow.me/tag/python.html">python</a>
</p>
</div>
</article>
<footer>
<p>
© 2017 - This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/deed.en_US" target="_blank">Creative Commons Attribution-ShareAlike</a>
</p>
<p>
Built with <a href="http://getpelican.com" target="_blank">Pelican</a> using <a href="http://bit.ly/flex-pelican" target="_blank">Flex</a> theme
</p><p>
<a rel="license"
href="http://creativecommons.org/licenses/by-sa/4.0/"
target="_blank">
<img alt="Creative Commons License"
title="Creative Commons License"
style="border-width:0"
src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"
width="80"
height="15"/>
</a>
</p> </footer>
</main>
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Blog",
"name": " Tonychow's Blog ",
"url" : "https://blog.tonychow.me",
"image": "/images/avatar.jpg",
"description": "tonychow's Thoughts and Writings"
}
</script>
</body>
</html>