From a3796489523e5b1372982fe702d2e35187c50e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=AE=E6=99=A8?= <362864550@qq.com> Date: Sat, 17 Nov 2018 13:24:50 +0800 Subject: [PATCH] EX.Class attributes and instance attributes --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 86fbc08..7706296 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ So, here we go... - [> Half triple-quoted strings/三个引号](#-half-triple-quoted-strings三个引号) - [> Midnight time doesn't exist?/不存在的午夜?](#-midnight-time-doesnt-exist不存在的午夜) - [> What's wrong with booleans?/布尔你咋了?](#-whats-wrong-with-booleans布尔你咋了) - - [> Class attributes and instance attributes](#-class-attributes-and-instance-attributes) + - [> Class attributes and instance attributes/类属性和实例属性](#-class-attributes-and-instance-attributes类属性和实例属性) - [> yielding None](#-yielding-none) - [> Mutating the immutable!](#-mutating-the-immutable) - [> The disappearing variable from outer scope](#-the-disappearing-variable-from-outer-scope) @@ -831,7 +831,7 @@ another_dict[1.0] = "Python" --- -### > Class attributes and instance attributes +### > Class attributes and instance attributes/类属性和实例属性 1\. ```py @@ -894,10 +894,10 @@ True True ``` -#### 💡 Explanation: +#### 💡 说明: -* Class variables and variables in class instances are internally handled as dictionaries of a class object. If a variable name is not found in the dictionary of the current class, the parent classes are searched for it. -* The `+=` operator modifies the mutable object in-place without creating a new object. So changing the attribute of one instance affects the other instances and the class attribute as well. +* 类变量和实例变量在内部是通过类对象的字典来处理(译: 就是 `__dict__` 属性). 如果在当前类的字典中找不到的话就去它的父类中寻找. +* `+=` 运算符会在原地修改可变对象, 而不是创建新对象. 因此, 在这种情况下, 修改一个实例的属性会影响其他实例和类属性. ---