回答編集履歴

1

追記

2018/06/30 13:59

投稿

hayataka2049
hayataka2049

スコア30933

test CHANGED
@@ -89,3 +89,45 @@
89
89
  ```
90
90
 
91
91
  の方が直感的かもしれません(結果は同じ)。
92
+
93
+
94
+
95
+
96
+
97
+ ### 追記
98
+
99
+ 文字列の組み立て方については、
100
+
101
+
102
+
103
+ ```python
104
+
105
+ # format関数(index指定)
106
+
107
+ return "{0}の能力:HPは{1}、攻撃は{2}、防御は{3}、特功は{4}、特防は{5}、素早さは{6}である。第1タイプは{7}、第2タイプは{8}である。".format(
108
+
109
+ self.name,self.hp,self.pw,self.de,
110
+
111
+ self.spp,self.spd,self.spe,
112
+
113
+ self.type,self.type2)
114
+
115
+
116
+
117
+ # format関数(キーワード引数指定)
118
+
119
+ return "{name}の能力:HPは{hp}、攻撃は{pw}、防御は{de}、特功は{spp}、特防は{spd}、素早さは{spe}である。第1タイプは{type1}、第2タイプは{type2}である。".format(
120
+
121
+ name=self.name,hp=self.hp,pw=self.pw,de=self.de,
122
+
123
+ spp=self.spp,spd=self.spd,spe=self.spe,
124
+
125
+ type1=self.type,type2=self.type2)
126
+
127
+
128
+
129
+ # f-strings(python3.6以降でのみ使える機能)
130
+
131
+ return f"{self.name}の能力:HPは{self.hp}、攻撃は{self.pw}、防御は{self.de}、特功は{self.spp}、特防は{self.spd}、素早さは{self.spe}である。第1タイプは{self.type}、第2タイプは{self.type2}である。"
132
+
133
+ ```