python中的ord函数有什么用?用法是什么?

Admin 2021-09-15 群英技术资�

    今天给大家分享python中的ord函数的内容,下文将会给大家介绍ord()函数的作用及用法,对大家学习Python有一定的帮助,有这方面学习需要的朋友接下来跟随小编一起来学习一下吧�

    Python ord()函数 (Python ord() function)

    ord() function is a library function in Python, it is used to get number value from given character value, it accepts a character and returns an integer i.e. it is used to convert a character to an integer i.e. it is used to get the ASCII value of a given character.

    ord()函数是Python中的一个库函数,用于从给定字符值中获取数字值,它接受一个字符并返回一个整数,即用于将字符转换为整数,即用于获取ASCII给定字符的� �

    Syntax:

    句法�

ord(character)

    Parameter:character - character value to be converted in an integer value.

    参数� character-要转换为整数值的字符值�

    Return value: str - returns an integer value of given character.

    返回值: str -返回给定字符的整数值�

    Example:

    例:

Input:
val = 'A'
print(ord(val))

Output:
65

    Python code to convert a character into an integer (ASCII value)

    Python代码可将字符转换为整�(ASCII�)

# python code to demonstrate an example
# of ord() function
 
val = 'A'
print("ASCII code of ", val, " is = ", ord(val))
 
val = 'x'
print("ASCII code of ", val, " is = ", ord(val))
 
val = '@'
print("ASCII code of ", val, " is = ", ord(val))
 
val = '8'
print("ASCII code of ", val, " is = ", ord(val))

    Output

    输出�

ASCII code of  A  is =  65

ASCII code of  x  is =  120

ASCII code of  @  is =  64

ASCII code of  8  is =  56

    关于python中的ord函数的作用和用法就介绍到这,上述实例具有一定的借鉴价值,感兴趣的朋友可以参考学习,希望能对大家有帮助,想要了解更多python中的ord函数的内容,大家可以关注群英网络其它相关文章�

文本转载自脚本之�

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:[email protected]进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容�

猜你喜欢

成为群英会员,开启智能安全云计算之旅

立即注册
专业资深工程师驻�
7X24小时快速响�
一站式无忧技术支�
免费备案服务
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 � 0668-2555555
在线客服
微信公众号
返回顶部
返回顶部 返回顶部