英文文档:

chr(i)
  Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a', while chr(8364) returns the string '€'. This is the inverse of ord().
  The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16). ValueError will be raised if i is outside that range
说明:
  1. 函数返回整形参数值所对应的Unicode字符的字符串表示
>>> chr(97) #参数类型为整数
'a' >>> chr('97') #参数传入字符串时报错
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
chr('97')
TypeError: an integer is required (got type str) >>> type(chr(97)) #返回类型为字符串
<class 'str'>

  2. 它的功能与ord函数刚好相反

>>> chr(97)
'a'
>>> ord('a')
97

  3. 传入的参数值范围必须在0-1114111(十六进制为0x10FFFF)之间,否则将报ValueError错误

>>> chr(-1) #小于0报错
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
chr(-1)
ValueError: chr() arg not in range(0x110000) >>> chr(1114111)
'\U0010ffff' >>> chr(1114112) #超过1114111报错
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
chr(1114112)
ValueError: chr() arg not in range(0x110000)

简单描述

chr接收一个数字, 找到这个数字对应的ascii里的元素(只能接受数字)
a = chr(65)
print(a) #结果: A
ord()接收一个字符,返回这个字符对应的数字.(只能接受一个字符)
b = ord('a')
print(b) #结果: 97

内置函数值 -- chr() ord() -- 字符和ascii的转换的更多相关文章

  1. python内置函数值 -- chr() ord()

    chr()接收一个数字, 找到这个数字对应的ascii里的元素(只能接受数字) a = chr(65) print(a) #结果: A ord()接收一个字符,返回这个字符对应的数字.(只能接受一个字 ...

  2. Python中字符串String的基本内置函数与过滤字符模块函数的基本用法

    Python中字符串String的基本内置函数与用法 首先我们要明白在python中当字符编码为:UTF-8时,中文在字符串中的占位为3个字节,其余字符为一个字节 下面就直接介绍几种python中字符 ...

  3. python中字符与ascii码转换

    ASCII码转字符用chr()函数:  字符转ASCII码用ord()函数:  

  4. Python字符与ASCII码转换

    有两个内置函数,记得以前在<Python Cookbook>里看到过. >>>print ord('a') 97 >>>print chr(97) a

  5. js 字符与ascii码转换

    参考 http://www.jb51.net/article/43534.htm ' '.charCodeAt();  //字符转ascii String.fromCharCode(10);  //a ...

  6. Python内置函数(16)——ord

    英文文档: ord(c) Given a string representing one Unicode character, return an integer representing the U ...

  7. Python内置函数(48)——ord

    英文文档: ord(c) Given a string representing one Unicode character, return an integer representing the U ...

  8. Python标准库:内置函数chr(i)

    返回一个參数i表示的字符串. 比方,chr(97)返回字符"a".參数i的有效范围为0到1.114,111(0x10FFFF),其他范围的值会抛出异常ValueError. 与之相 ...

  9. js字母/字符与ASCII码转换

    var tempStr="A"; console.log(tempStr.charCodeAt());// 65 ,转ASCII码 console.log(String.fromC ...

随机推荐

  1. Spring MVC 配置文件dispatcher-servlet.xml 文件详解(转自 学无止境-yj)

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. asp.net core 部署到服务器之后外网访问不了

    部署发现问题 今天在部署.net core的时候,发现访问http://localhost:xxxx可以,但是用外网访问并不行! 开始尝试解决问题 一开始以为是nginx的问题.各种折腾,各种改配置文 ...

  3. word中正文分栏重新换页问题

    小论文常需要正文分栏,但是标题.摘要不分栏的编排格式. 1.在摘要后面加入分隔符来将内容分为摘要和正文两个部分.选择 插入→分隔符→分节符(连续). 2.然后进行分栏.选择 格式→分栏. 3.此时如果 ...

  4. Html的<meta>标签使用方法及用例

    浏览器支持 所有浏览器都支持 <meta> 标签. 定义和用法 <meta> 元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和 ...

  5. Electron应用使用electron-builder配合electron-updater实现自动更新(windows + mac)

    发客户端一定要做的就是自动更新模块,否则每次版本升级都是一个头疼的事.下面是Electron应用使用electron-builder配合electron-updater实现自动更新的解决方案. 1.安 ...

  6. shiro权限控制(二):分布式架构中shiro的实现

    前言:前段时间在搭建公司游戏框架安全验证的时候,就想到之前web最火的shiro框架,虽然后面实践发现在netty中不太适用,最后自己模仿shiro写了一个缩减版的,但是中间花费两天时间弄出来的shi ...

  7. 【原创】Struts2.5.12版本中使用通配符*

    ι 版权声明:本文为博主原创文章,未经博主允许不得转载. <package name="hellodemo" extends="struts-default&quo ...

  8. 在IAR下移植CC2650 contiki工程

    与Instant Contiki相比,在Windows的IAR下开发可以在线仿真,下载也更方便,因此我想把BLEach的工程移植到IAR下.弄了好几天总算编译并且下载成功了,参考了[这篇TI的wiki ...

  9. OS模块的常用内置方法

    chdir 修改当前工作目录到指定目录 Change the current working directory to the specified path. chmod 修改一个文件的访问权限 Ch ...

  10. 解决Bug:Size of a request header field exceeds server limit

    用了cms 发现这玩意真不好,老是有各种奇芭的问题跳出来 有时浏览网页时会出现 Bad Request Your browser sent a request that this server cou ...