您当前的位置: 首页 >  Python

IT之一小佬

暂无认证

  • 3浏览

    0关注

    1192博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

python 中的ord()函数和chr()函数

IT之一小佬 发布时间:2021-01-07 20:02:40 ,浏览量:3

python 中的ord()函数和chr()函数

        需要对字符进行转换时使用 其中ord函数可以将字符转化为你所需要的ASCII码,chr函数可以将0-255中的任一整数转化为你所需要的字符。

通过这样的转化 你可以方便的完成字符与数字之间的转换操作,更好使用for循环以及if判断等常用操作。

示例代码如下:

print(ord("a"))
print(ord("b"))
print(ord("A"))
print(ord("B"))
print(chr(97))
print(chr(98))

运行结果为:

97
98
65
66
a
b

 

关注
打赏
1665675218
查看更多评论
立即登录/注册

微信扫码登录

0.0386s