python中文utf8编码后是占3个字符,unicode汉字为2字节
2015-08-16 22:38
816 查看
一个中文utf8编码后是占3个字符,所以求长度的函数可以这样写 def str_len(str): try: row_l=len(str) utf8_l=len(str.encode('utf-8')) return (utf8_l-row_l)/2+row_l except: return None return None unicode中汉字为两字节, utf-8中汉字为三字节
https://en.wikipedia.org/wiki/Unicode
https://en.wikipedia.org/wiki/UTF-8
相关文章推荐
- 从底层简析Python程序的执行过程
- Python Web 实战 - 搭建Django环境和初步使用
- 从底层简析Python程序的执行过程
- vijos - P1286座位安排 (DP状态压缩 + 组合数 + python)
- python xpath
- python xpath
- 用Python 爬虫批量下载PDF文档
- splinter python浏览器自动化操作,模拟浏览器的行为
- splinter python浏览器自动化操作,模拟浏览器的行为
- python2+opencv2做图像处理
- Python 之 使用 PIL 库做图像处理
- python验证码识别
- Python 之 使用 PIL 库做图像处理
- python验证码识别
- python对文件的读取操作方式比较
- python修饰器
- 利用Python和goagent代理爬取1024帖子所有图片
- 零基础学python-4.1 python对象的简介和标准类型
- 零基础学python-4.1 python对象的简介和标准类型
- python按照表修改excel中的内容