python中ord/chr函数实现ASCII值与字符之间的切换

在很多时候需要获取某些字母的ASCII值或者是已知ASCII值想要知道对应的字符是什么,其中python中有两个函数分别是ord/chr函数可以实现ASCII值与字符之间的切换。ord函数可以获取一个字母的ascii值,chr函数可以将ascii值转换为字符

if __name__ == '__main__':
    print(ord("a"))
    print(ord("A"))

    print(chr(97))
    print(chr(66))

猜你喜欢

转载自blog.csdn.net/qq_39445165/article/details/115146877