1 |
print("NumPy array: \n {}".format(aaa)) |
1 |
print("NumPy array: \n {}".format(aaa)) |
len(変数)
1 2 3 4 5 6 7 8 9 |
%d -> 整数で表示 %f -> 小数で表示 %.2f -> 小数第2位まで表示 %s -> 文字列として表示 |
(例)
1 2 3 |
<span class="cm-variable">pai</span> = <span class="cm-number">3.141592</span> <span class="cm-builtin">print</span>(<span class="cm-string">"円周率は%f"</span> <span class="cm-operator">%</span> <span class="cm-variable">pai</span>) <span class="cm-comment"># 円周率は3.141592と出力されます。</span> <span class="cm-builtin">print</span>(<span class="cm-string">"円周率は%.2f"</span> <span class="cm-operator">%</span> <span class="cm-variable">pai</span>) <span class="cm-comment"># 円周率は3.14と出力されます。</span> |
fruit = "banana"
color = "yellow"
print("{0}は{1}です".format("banana","yellow"))
1 2 3 4 5 |
<span class="cm-variable">city</span> = <span class="cm-string">"Tokyo"</span> <span class="cm-builtin">print</span>(<span class="cm-variable">city</span>.<span class="cm-property">count</span>(<span class="cm-string">"o"</span>)) <span class="cm-comment"># 2と出力されます。 リストの場合 (["山形","山梨","山口","山形","山梨","山口"],"山")</span> |
というのはできない、リストでは部分一致ではなく完全一致
1 2 3 4 |
<span class="cm-variable">alphabet</span> = [<span class="cm-string">"a"</span>,<span class="cm-string">"d"</span>,<span class="cm-string">"e"</span>,<span class="cm-string">"c"</span>,<span class="cm-string">"b"</span>] <span class="cm-builtin">sorted</span>(<span class="cm-variable">alphabet</span>) <span class="cm-builtin">print</span>(<span class="cm-variable">alphabet</span>) |
adecbの順番で出力
1 2 3 4 5 |
<span class="cm-variable">alphabet</span> = [<span class="cm-string">"a"</span>,<span class="cm-string">"d"</span>,<span class="cm-string">"e"</span>,<span class="cm-string">"c"</span>,<span class="cm-string">"b"</span>] <span class="cm-variable">alphabet</span>.<span class="cm-property">sort</span>() <span class="cm-builtin">print</span>(<span class="cm-variable">alphabet</span></code><code class="cm-s-ipython language-python">)</code><code class="cm-s-ipython language-python"> abcdeの順番で出力 |