Python 中的 ASCII 转换

ASCII conversion in Python

我正在制作一个加密程序,如果我可以使用 ascii 数字来表示一个字符,那么制作起来会非常容易。(使用现在已弃用的 string.translate)有没有办法通过它传递一个字符ascii 数字,然后将其附加到字符串?

我想你在找 chr:

Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range. See also unichr().

ord

Given a string of length one, return an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string.

示例:

print("somestring" + chr(65)) # prints "somestringA"