2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -4,7 +4,7 @@
In [1]:
```
```py
x = [1, 2, 3]
y = x
x[1] = 100
@@ -12,7 +12,7 @@ print y
```
```
```py
[1, 100, 3]
```
@@ -23,7 +23,7 @@ print y
先来看这一段代码在**Python**中的执行过程。
```
```py
x = 500
y = x
y = 'foo'
@@ -59,7 +59,7 @@ y = 'foo'
对这一过程进行验证,可以使用 `id` 函数。
```
```py
id(x)
```
@@ -67,7 +67,7 @@ id(x)
In [2]:
```
```py
x = 500
id(x)
@@ -75,13 +75,13 @@ id(x)
Out[2]:
```
```py
48220272L
```
In [3]:
```
```py
y = x
id(y)
@@ -89,7 +89,7 @@ id(y)
Out[3]:
```
```py
48220272L
```
@@ -97,14 +97,14 @@ Out[3]:
In [4]:
```
```py
x is y
```
Out[4]:
```
```py
True
```
@@ -112,7 +112,7 @@ True
In [5]:
```
```py
y = 'foo'
id(y)
@@ -120,20 +120,20 @@ id(y)
Out[5]:
```
```py
39148320L
```
In [6]:
```
```py
x is y
```
Out[6]:
```
```py
False
```
@@ -141,7 +141,7 @@ False
In [7]:
```
```py
x = 500
id(x)
@@ -149,13 +149,13 @@ id(x)
Out[7]:
```
```py
48220296L
```
In [8]:
```
```py
y = 500
id(y)
@@ -163,20 +163,20 @@ id(y)
Out[8]:
```
```py
48220224L
```
In [9]:
```
```py
x is y
```
Out[9]:
```
```py
False
```
@@ -184,7 +184,7 @@ False
In [10]:
```
```py
x = 2
id(x)
@@ -192,13 +192,13 @@ id(x)
Out[10]:
```
```py
6579504L
```
In [11]:
```
```py
y = 2
id(y)
@@ -206,20 +206,20 @@ id(y)
Out[11]:
```
```py
6579504L
```
In [12]:
```
```py
x is y
```
Out[12]:
```
```py
True
```
@@ -227,7 +227,7 @@ True
现在来看另一段代码:
```
```py
x = [500, 501, 502]
y = x
y[1] = 600
@@ -292,7 +292,7 @@ Python为3个PyInt分配内存 `pos1` `pos2` `pos3` (不可变),
In [13]:
```
```py
x = [500, 501, 502]
print id(x[0])
print id(x[1])
@@ -301,7 +301,7 @@ print id(x)
```
```
```py
48220224
48220248
48220200
@@ -313,27 +313,27 @@ print id(x)
In [14]:
```
```py
y = x
print id(y)
```
```
```py
54993032
```
In [15]:
```
```py
x is y
```
Out[15]:
```
```py
True
```
@@ -341,13 +341,13 @@ True
In [16]:
```
```py
y[1] = 600
print id(y)
```
```
```py
54993032
```
@@ -356,13 +356,13 @@ print id(y)
In [17]:
```
```py
print id(x[1])
print id(y[1])
```
```
```py
48220272
48220272
@@ -372,14 +372,14 @@ print id(y[1])
In [18]:
```
```py
y = [700, 800]
print id(y)
print id(x)
```
```
```py
54995272
54993032