加入收藏 | 设为首页 | 会员中心 | 我要投稿 济源站长网 (https://www.0391zz.cn/)- 数据工具、数据仓库、行业智能、CDN、运营!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

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

发布时间:2022-02-19 13:45:46 所属栏目:语言 来源:互联网
导读:今天给大家分享python中的ord函数的内容,下文将会给大家介绍ord()函数的作用及用法,对大家学习Python有一定的帮助,有这方面学习需要的朋友接下来跟随小编一起来学习一下吧。 Python ord()函数 (Python ord() function) ord() function is a library funct
    今天给大家分享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

(编辑:济源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读