サンプル
- lengthなどはint
- spirintfでまとめつつStringにしている
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<span class="k">package</span> <span class="n">main</span> <span class="k">import</span> <span class="s">"fmt"</span> <span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span> <span class="k">type</span> <span class="n">sample</span> <span class="k">struct</span> <span class="p">{</span> <span class="n">length</span> <span class="kt">int</span> <span class="n">Height</span> <span class="kt">int</span> <span class="p">}</span> <span class="n">p</span> <span class="o">:=</span> <span class="nb">new</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span> <span class="n">p</span><span class="o">.</span><span class="n">length</span> <span class="o">=</span> <span class="m">13</span> <span class="n">p</span><span class="o">.</span><span class="n">Height</span> <span class="o">=</span> <span class="m">666</span> <span class="n">str</span> <span class="o">:=</span> <span class="n">fmt</span><span class="o">.</span><span class="n">Sprintf</span><span class="p">(</span><span class="s">"長さ:%d 高さ:%d"</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">length</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">Height</span><span class="p">)</span> <span class="n">fmt</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="n">str</span><span class="p">)</span> <span class="p">}</span> |
結果
1 |
長さ:13 高さ:666 |