Golang隨手筆記 struct
初始化
用雙引號帶值的方式設置初值。
package main
import (
"fmt"
)
type Car struct {
model string
horse_power float32
toque int
}
func main() {
var mycar Car
mycar = Car{"WRX STi", 300.8, 407}
fmt.Println(mycar)
result := fmt.Sprintf("My Car is model %s, it has %.1f HP and max toque %d Nm.", mycar.model, mycar.horse_power, mycar.toque)
fmt.Println(result)
}
Filed under: Golang - @ 2021 年 6 月 22 日 下午 5:39
標籤: golang