【发布时间】:2019-05-07 05:48:59
【问题描述】:
我有多个存储一些文本数据的字符串变量。我想对所有字符串执行相同的任务集。如何在 Python 中实现这一点?
string_1 = "this is string 1"
string_2 = "this is string 2"
string_3 = "this is string 3"
for words in string_1:
return the second word
以上只是一个例子。我想提取每个字符串中的第二个单词。我可以这样做吗:
for words in [string_1, string_2, string_3]:
return the second word in each string
【问题讨论】:
标签: python-3.x string for-loop