本文介绍了python的ord(),chr()在等同于go?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python的和函数?

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


解决方案

它们支持简单的:

  ch:= rune(97)
n:= int('a ')
fmt.Printf(char:%c \ n,ch)
fmt.Printf(code:%d\\\
,n)

输出(尝试在):

  char:a 
code:97
code>

注意:您也可以将,它基本上将整数值解释为UTF-8编码值:

 s:= string(97)
fmt.Printf(text:%s\,s)//输出:text:a

$ b


What is the equivalent of python's chr() and ord() functions in golang?

chr(97) = 'a'
ord('a') = 97
解决方案

They are supported as simple conversions:

ch := rune(97)
n := int('a')
fmt.Printf("char: %c\n", ch)
fmt.Printf("code: %d\n", n)

Output (try it on the Go Playground):

char: a
code: 97

Note: you can also convert an integer numeric value to a string which basically interprets the integer value as the UTF-8 encoded value:

s := string(97)
fmt.Printf("text: %s\n", s) // Output: text: a

这篇关于python的ord(),chr()在等同于go?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:12