4.4. 字符串常用内置函数

字符串也可以使用: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
喜欢就支持一下吧
点赞11 分享
评论 抢沙发
头像-大赛人网
欢迎您留下宝贵的见解!
提交
头像-大赛人网

昵称

取消
昵称

    请登录后查看评论内容