为字符串中的每个空格创建 for 语句

可能是一个菜鸟问题,但我如何为字符串中的每个空格创建 for 语句?


text = "Hello World, this is a string!"

for spaces in text

    # do blah blah


小怪兽爱吃肉
浏览 110回答 1
1回答

桃花长相依

获取for循环中的每个字符并使用if条件检查它是否为空格text = "Hello World, this is a string!"for character in text: if character == " ":    # do blah blah
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python