首页 > 新闻中心 > 技术百科

python如何计算字符串的长度,python中字符串长度咋计算 返回列表

网络2023-08-28 00:00:00编辑发布,已经有个小可爱看过这篇文章啦

python 计算字符串长度,一个中文算两个字符,先转换成utf8,然后通过计算utf8的长度和len函数取得的长度,进行对比即可知道字符串内中文字符的数量,自然就可以计算出字符串的长度了。

value=u\’脚本12\’length = len(value)utf8_length = len(value.encode(\’utf-8\’))length = (utf8_length – length)/2 + lengthprint(length)

结果输出:

634396833

《python如何计算字符串的长度,python中字符串长度咋计算》来自互联网同行内容,若有侵权,请联系我们删除!

  • 互联网
  • img
  • src
  • 就可以
  • python
  • aliyucs
  • hongkong
  • cn
  • space
  • oss

热门新闻

来电咨询