Python内置函数(10)——chr
英文文档:
chr(i)- Return the string representing a character whose Unicode code point is the integer i. For example,
chr(97)returns the string'a', whilechr(8364)returns the string'€'. This is the inverse oford(). - The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16).
ValueErrorwill 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的更多相关文章
- Python内置函数(17)——chr
英文文档: chr(i) Return the string representing a character whose Unicode code point is the integer i. F ...
- Python内置函数(10)——float
英文文档: class float([x]) Return a floating point number constructed from a number or string x. If the ...
- Python内置函数之chr()
参数是一个整型对象: chr(integer) 返回整型对应的Unicode字符对象. 例子: >>> chr() '\x0c' >>> chr() 'ⲓ' > ...
- python内置函数
python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...
- python 内置函数和函数装饰器
python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...
- Python内置函数进制转换的用法
使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...
- Python 内置函数笔记
其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...
- 【转】python 内置函数总结(大部分)
[转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...
- python内置函数,匿名函数
一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...
随机推荐
- 网站发布出现“未能找到路径“path\bin\roslyn\csc.exe”....“和拒绝访问的解决办法
最近在2017上新建了一个MVC项目,发布是出现了各种奇怪的问题,其中一个错误是: 未能找到路径“path\bin\roslyn\csc.exe”.... 经过网上搜寻资料发现罪魁祸首就是NUGET里 ...
- zabbix4.0监控Mysql数据库
#wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.11-1.el7.x86_64.rpm #rpm -ivh ...
- 了解 ptyhon垃圾回收机制
Python的GC模块主要运用了“引用计数”(reference counting)来跟踪和回收垃圾.在引用计数的基础上,还可以通过“标记-清除”(mark and sweep)解决容器对象可能产生的 ...
- sklearn库 线性回归库 LinearRegression
import numpy as np import sklearn.datasets #加载原数据 from sklearn.model_selection import train_test_spl ...
- linux安装vsftp服务
如果管理一个网站,需要经常上传下载一些文件,通过scp传输吗?当然不是,太麻烦了,而且首先你需要本机是linux的系统,这时我们需要一个工具,叫ftp. ftp是文件传输协议,通过它可以很方便上传下载 ...
- 我的BO之强类型
弱类型的缺点 有些程序员对类型比较随意,从前端传来的数据,不管应该是什么类型,都以String接收.然后在什么地方转成应该有的类型则要"看心情",在Controller, Serv ...
- spring 应用
Spring框架本身会托管bean. 1.使用时需要注意对于包本身扫描配置. 2.使用注解本身包需要在扫描路径下.
- CF.802C.Heidi and Library (hard) (费用流zkw)
题目链接 复习了下餐巾计划问题.全忘了=-= 首先这是一道网络流.然后本题有\(n\)种建图方法,以及\(smy\) dalao还有单纯形做法. 先假设所有物品都是买入的.那么对于每一天,拆成两个点\ ...
- [Ubuntu]Firefox书签Ubuntu与Windows同步
Ubuntu默认使用Firefox国际版.其他平台访问官网下载到的都是中国版,而国际版和中国版使用两套账号体系,相互之间无法同步,导致Ubuntu的Firefox无法和其他平台的Firefox同步书签 ...
- wordcount源代码详解
package wordcount; import java.io.IOException; import java.util.StringTokenizer; import org.apache.h ...