我對 Go 編程語言相當不熟悉,我一直在試圖找到一種方法來將變量的類型作為字符串獲取。到目前為止,我還沒有找到任何有效的方法。我曾嘗試使用typeof(variableName)以字符串形式獲取變量的類型,但這似乎無效。Go 有沒有內置的運算符可以獲取變量的類型作為字符串,類似于 JavaScript 的typeof運算符或 Python 的type運算符?//Trying to print a variable's type as a string:package mainimport "fmt"func main() { num := 3 fmt.Println(typeof(num)) //I expected this to print "int", but typeof appears to be an invalid function name.}
在 Go 編程語言中,是否可以以字符串的形式獲取變量的類型?
慕田峪7331174
2021-06-15 21:01:27