python基础--字符与编号

1.每个字符都有其编号,根据字符求编号用ord

ch1='A'
print(ord(ch1))

运行

65

Process finished with exit code 0

2.根据标号找字符用chr

print(chr(98))

运行

b

Process finished with exit code 0

print(chr(25105))

运行

注:每个字符都有编号的,不光asc码表上的数字字母符号,就连汉字都有编号的,可以尝试下

3.统一码\u

同样的输出字符--我,还可以用用十六进制的方式显示

25105的十六进制显示是6211

所以可以这样打印出字符我:

print("\u6211")

运行

3.python里没字符类型,只有字符串

ch1='A'
print(ord(ch1))
print(type(ch1))

运行

65
<class 'str'>

Process finished with exit code 0
 

发布了31 篇原创文章 · 获赞 10 · 访问量 267

猜你喜欢

转载自blog.csdn.net/qq_34240459/article/details/105087242