Python 判断字符串长度

Document 对象参考手册 Python3 实例

给定一个字符串,然后判断改字符串的长度。

实例 1:使用内置方法 len()

str = "icodebang"
print(len(str))

执行以上代码输出结果为:

6

实例 2:使用循环计算

def findLen(str): 
 counter = 0
 while str[counter:]: 
 counter += 1
 return counter 
 
str = "icodebang"
print(findLen(str))

执行以上代码输出结果为:

6

Document 对象参考手册 Python3 实例

0 个评论

要回复文章请先登录注册