# 示例代码:使用 ord() 函数
# ord() 函数用于获取字符的 Unicode 码位(integer representing the Unicode code point)
# 示例 1: 获取单个字符的 Unicode 码位
char = 'A'
unicode_code_point = ord(char)
print(f"字符 '{char}' 的 Unicode 码位是: {unicode_code_point}")
# 示例 2: 获取多个字符的 Unicode 码位
for char in "Hello":
print(f"字符 '{char}' 的 Unicode 码位是: {ord(char)}")
ord()
函数接受一个字符串参数,该字符串必须是一个单一字符(长度为1),并返回该字符对应的 Unicode 码位。'A'
的 Unicode 码位,并将其打印出来。"Hello"
中的每个字符,并分别输出它们的 Unicode 码位。上一篇:网络爬虫python代码
下一篇:python循环结构for循环
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站