回答編集履歴
2
fix example code
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
self.age = age
|
22
22
|
|
23
|
-
def __str__():
|
23
|
+
def __str__(self):
|
24
24
|
|
25
25
|
return f'PersonA(name={self.name}, age={self.age})'
|
26
26
|
|
@@ -50,11 +50,11 @@
|
|
50
50
|
|
51
51
|
self.age = age
|
52
52
|
|
53
|
-
def __str__():
|
53
|
+
def __str__(self):
|
54
54
|
|
55
55
|
return f'PersonA(name={self.name}, age={self.age})'
|
56
56
|
|
57
|
-
def pretty_str():
|
57
|
+
def pretty_str(self):
|
58
58
|
|
59
59
|
return f'{self.name}は{self.age}歳です'
|
60
60
|
|
@@ -105,3 +105,7 @@
|
|
105
105
|
|
106
106
|
|
107
107
|
どの方法を使うか人やプロジェクトそれぞれです。自分で色々試してください!
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
Update: コード例を修正しました。
|
1
add usage
test
CHANGED
@@ -16,13 +16,21 @@
|
|
16
16
|
|
17
17
|
def __init__(self, name, age):
|
18
18
|
|
19
|
-
self.
|
19
|
+
self.name = name
|
20
20
|
|
21
|
-
self.
|
21
|
+
self.age = age
|
22
22
|
|
23
23
|
def __str__():
|
24
24
|
|
25
|
-
return f'PersonA(
|
25
|
+
return f'PersonA(name={self.name}, age={self.age})'
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
a = PersonA('太郎', 10)
|
30
|
+
|
31
|
+
print(a)
|
32
|
+
|
33
|
+
# PersonA(name='太郎', age=10)
|
26
34
|
|
27
35
|
```
|
28
36
|
|
@@ -38,17 +46,29 @@
|
|
38
46
|
|
39
47
|
def __init__(self, name, age):
|
40
48
|
|
41
|
-
self.
|
49
|
+
self.name = name
|
42
50
|
|
43
|
-
self.
|
51
|
+
self.age = age
|
44
52
|
|
45
53
|
def __str__():
|
46
54
|
|
47
|
-
return f'PersonA(
|
55
|
+
return f'PersonA(name={self.name}, age={self.age})'
|
48
56
|
|
49
57
|
def pretty_str():
|
50
58
|
|
51
|
-
return f'{self.
|
59
|
+
return f'{self.name}は{self.age}歳です'
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
a = PersonA('太郎', 10)
|
64
|
+
|
65
|
+
print(a)
|
66
|
+
|
67
|
+
# PersonA(name='太郎', age=10)
|
68
|
+
|
69
|
+
print(a.pretty_str())
|
70
|
+
|
71
|
+
# 太郎は10歳です
|
52
72
|
|
53
73
|
```
|
54
74
|
|
@@ -64,7 +84,21 @@
|
|
64
84
|
|
65
85
|
def __str__():
|
66
86
|
|
67
|
-
return f'{self.
|
87
|
+
return f'{self.name}は{self.age}歳です'
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
a = PersonA('太郎', 10)
|
92
|
+
|
93
|
+
print(a)
|
94
|
+
|
95
|
+
# PersonA(name='太郎', age=10)
|
96
|
+
|
97
|
+
ap = PersonAPrettier(a)
|
98
|
+
|
99
|
+
print(ap)
|
100
|
+
|
101
|
+
# 太郎は10歳です
|
68
102
|
|
69
103
|
```
|
70
104
|
|