字符串也可以使用:max、min、len、sorted、sum函数,但实际开发中len函数最常用。
msg = 'welcome to dsrw'
result = len(msg)
print(result)
print(result) # 15
4.5. 遍历字符串
字符串的遍历,与列表一样,可以使用while循环遍历,或for循环遍历。
msg = 'welcome to dsrw'
# while循环遍历
index = 0
while index < len(msg):
print(msg[index])
index += 1
# for循环遍历
for item in msg:
print(item)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END















请登录后查看评论内容