英文文档:

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('') #参数传入字符串时报错
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
chr('')
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)

Python内置函数(10)——chr的更多相关文章

  1. Python内置函数(17)——chr

    英文文档: chr(i) Return the string representing a character whose Unicode code point is the integer i. F ...

  2. Python内置函数(10)——float

    英文文档: class float([x]) Return a floating point number constructed from a number or string x. If the ...

  3. Python内置函数之chr()

    参数是一个整型对象: chr(integer) 返回整型对应的Unicode字符对象. 例子: >>> chr() '\x0c' >>> chr() 'ⲓ' > ...

  4. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

  5. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  6. Python内置函数进制转换的用法

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...

  7. Python 内置函数笔记

    其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...

  8. 【转】python 内置函数总结(大部分)

    [转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...

  9. python内置函数,匿名函数

    一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...

随机推荐

  1. C# Post方式下,取得其它端传过来的数据

    // Post方式下,取得java端传过来的数据 if ("post".Equals(context.Request.HttpMethod.ToLower())) { contex ...

  2. 小程序-组件component和模版template的选择和使用

    小程序提供了组件component和模版template那什么时候 选择哪一个使用呢?我总结了一下 template主要是模版,对于重复的展示型模块进行展示,其中调用的方法或者数据data都是需要引用 ...

  3. docker 安装 hbase安装 java连接hbase (mac环境)

    docker 安装 https://hub.docker.com/editions/community/docker-ce-desktop-mac 下载地址 下载完之后,安装app一样安装就好 安装完 ...

  4. vue与avuex

    现在 使用avuex做出来表格效果,但是看到源码看到需要使用vue,不得不开始学习vue 配置环境:cnpm配置过程:a:首先下载node.js然后根据https://www.cnblogs.com/ ...

  5. spring为什么推荐使用构造器注入?

    闲谈 ​ Spring框架对Java开发的重要性不言而喻,其核心特性就是IOC(Inversion of Control, 控制反转)和AOP,平时使用最多的就是其中的IOC,我们通过将组件交由Spr ...

  6. C++第三课:类的使用(一)[个人见解]

    说到C++语言的类,也称对象.在C++中首先得了解的三大特性:继承.封装.多态. 使用C++类,间接的反映出你所学习C++的深度,这章很重要,但小编未必能全部讲到,还望谅解. 类是C++语言中新添加的 ...

  7. HDU-AcmKeHaoWanLe训练实录

    菜鸡队训练实录. 现场赛记录:[名称:奖项/排名] 2017: ICPC Shenyang:Gold/3 CCPC Hangzhou:Gold/3 ICPC Beijing:Gold/13 CCPC ...

  8. 181102 Python环境搭建(安装Sublime Text3)

    利用Pycharm来编写.执行python代码是一个不错的选择,Pycharm的安装的确也很方便.但是偶然看到别人用Sublime Text来编写.执行代码,觉得很酷.所以自己动手搭建环境. 1. 下 ...

  9. Anaconda虚拟环境

    创建虚拟环境:conda create -n env_name packages 例:创建名为env1的虚拟环境,并在其中安装numpy,conda create -n env1 numpy. 指定特 ...

  10. php GD库快速消耗CPU资源漏洞 CVE-2018-5711测试

    漏洞说明: 用一张GIF图片就可导致服务器发生崩溃直至宕机,在现实中非常容易利用. 影响版本: PHP 5 < 5.6.33 PHP 7.0 < 7.0.27 PHP 7.1 < 7 ...