Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
相当于python';s ord(),chr()在go中?_Go - Fatal编程技术网

相当于python';s ord(),chr()在go中?

相当于python';s ord(),chr()在go中?,go,Go,在golang中,python和函数的等价物是什么 chr(97) = 'a' ord('a') = 97 它们的支持方式很简单: 输出(在上尝试): 注意:您还可以转换一个基本上将整数值解释为UTF-8编码值的值: s := string(97) fmt.Printf("text: %s\n", s) // Output: text: a 将有符号或无符号整数值转换为字符串类型将生成一个包含整数UTF-8表示形式的字符串。超出有效Unicode代码点范围的值将转换为“\uFFFD” 似乎简

在golang中,python和函数的等价物是什么

chr(97) = 'a'
ord('a') = 97

它们的支持方式很简单:

输出(在上尝试):

注意:您还可以转换一个基本上将整数值解释为UTF-8编码值的值:

s := string(97)
fmt.Printf("text: %s\n", s) // Output: text: a
将有符号或无符号整数值转换为字符串类型将生成一个包含整数UTF-8表示形式的字符串。超出有效Unicode代码点范围的值将转换为
“\uFFFD”


似乎简单的
uint8('a')
将产生正确的输出。要将整数转换为字符串
string(98)
即可:

uint8('g') // 103
string(112) // p
s := string(97)
fmt.Printf("text: %s\n", s) // Output: text: a
uint8('g') // 103
string(112) // p