Python 判断字符串长度
Python 判断字符串长度的例子
给定一个字符串,然后判断改字符串的长度。
# Filename : example.py
# DateTime : 2020-07-20
# author by : www.lidihuo.com
str = "lidihuo"
print(len(str))
执行以上代码输出结果为:
使用while 循环计算
# Filename : example.py
# DateTime : 2020-07-20
# author by : www.lidihuo.com
def findLen(str):
counter = 0
while str[counter:]:
counter += 1
return counter
str = "lidihuo"
print(findLen(str))
执行以上代码输出结果为: