回答編集履歴
2
説明の修正
answer
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
代入は「変数名 = オブジェクト」という形です。
|
2
2
|
オブジェクトは、ID と型と値を持っています。
|
3
|
-
代入によって、オブジェクトの ID が変数に保存され
|
3
|
+
代入によって、オブジェクトの ID が変数に保存されると考えると分かりやすいでしょう。
|
4
4
|
オブジェクトは、定数であったり、変数であったり、演算結果だったりします。
|
5
5
|
|
6
6
|
次のコードを見てどう思いますか?
|
1
定数を追加
answer
CHANGED
@@ -5,9 +5,11 @@
|
|
5
5
|
|
6
6
|
次のコードを見てどう思いますか?
|
7
7
|
```Python
|
8
|
+
print(id(123), type(123), 123)
|
9
|
+
print(id('abc'), type('abc'), 'abc')
|
8
10
|
a = 123; print(id(a), type(a), a)
|
11
|
+
a = 'abc'; print(id(a), type(a), a)
|
9
12
|
a = 3.14; print(id(a), type(a), a)
|
10
|
-
a = 'abc'; print(id(a), type(a), a)
|
11
13
|
a = [1,2,3]; print(id(a), type(a), a)
|
12
14
|
a = {'a':1, 'b':2, 'c':3}; print(id(a), type(a), a)
|
13
15
|
a = 100 + 23; print(id(a), type(a), a)
|
@@ -23,14 +25,16 @@
|
|
23
25
|
実行結果
|
24
26
|
```text
|
25
27
|
9760128 <class 'int'> 123
|
26
|
-
140462186846896 <class 'float'> 3.14
|
27
|
-
|
28
|
+
140048904384304 <class 'str'> abc
|
28
|
-
140462185246336 <class 'list'> [1, 2, 3]
|
29
|
-
140462186625408 <class 'dict'> {'a': 1, 'b': 2, 'c': 3}
|
30
29
|
9760128 <class 'int'> 123
|
31
|
-
|
30
|
+
140048904384304 <class 'str'> abc
|
31
|
+
140048904641200 <class 'float'> 3.14
|
32
|
+
140048903040832 <class 'list'> [1, 2, 3]
|
33
|
+
140048904419712 <class 'dict'> {'a': 1, 'b': 2, 'c': 3}
|
34
|
+
9760128 <class 'int'> 123
|
35
|
+
140048904384304 <class 'str'> abc
|
32
|
-
|
36
|
+
140048903040704 <class 'list'> [1, 2, 3]
|
33
|
-
|
37
|
+
140048904812960 <class 'builtin_function_or_method'> <built-in function len>
|
34
38
|
9450080 <class 'type'> <class 'int'>
|
35
39
|
9451200 <class 'type'> <class 'str'>
|
36
40
|
9426528 <class 'type'> <class 'list'>
|