如何在Golang中使用内置方法?

如何在Golang中使用内置方法?,go,Go,我正在尝试以下简单代码: var f1 float64 = 23.435 fmt.Println(f1.Acos()) 但它给了我以下错误: f1.Acos undefined (type float64 has no field or method Acos) 有谁能帮助我理解使用内置方法的正确方法吗 Acos是math包的函数,不是float64的内置方法,因此必须先导入它 import ( "fmt" "math" ) 然后,将f1作为参数传递给math.Acos f

我正在尝试以下简单代码:

var f1 float64 = 23.435
fmt.Println(f1.Acos())
但它给了我以下错误:

f1.Acos undefined (type float64 has no field or method Acos)

有谁能帮助我理解使用内置方法的正确方法吗

Acos
math
包的函数,不是float64的内置方法,因此必须先导入它

import (
    "fmt"
    "math"
)
然后,将
f1
作为参数传递给
math.Acos

fmt.Println(math.Acos(f1))

首先,试着理解语言。您需要为
math.Acos()
函数提供一个float64值。正确的方法:
math.Acos(f1)