在JavaScript中,我可以执行以下操作:
const periods = {
'mercury': 0.2408467,
'venus': 0.61519726,
'earth': 1.0,
'mars': 1.8808158,
'jupiter': 11.862615,
'saturn': 29.447498,
'uranus': 84.016846,
'neptune': 164.79132,
};
const planetName = prompt();
const period = periods[planetName];
如何在go-lang中做类似的事情?
您接近回答自己的问题。 :)
只需将这些标签放在Google上即可。
package main
import (
"fmt"
)
func main() {
periods := map[string]float32{
"mercury": 0.2408467,
"venus": 0.61519726,
}
fmt.Println(periods["mercury"])
}