立马中头奖

导航

Python获取字符串长度_201117

字符串长度

可使用len()函数计算字符串长度,基本语法格式为:

len(string)

举例:定义字符串'i want to go to bed',计算其长度

a='i want to go to bed'
print(len(a))
>>>19

字符串字节数

>>> str1 = "人生苦短,我用Python"
>>> len(str1.encode())
27

 

posted on 2020-11-17 18:03  立马中头奖  阅读(919)  评论(0编辑  收藏  举报