foreach list中的每一个字符串
可以使用for循环来遍历列表中的每个字符串,例如:
my_list = ['hello', 'world', 'python']
for string in my_list:
print(string)
输出结果为:
hello
world
python
在循环体内,可以对每个字符串进行需要的操作,例如对每个字符串进行大小写转换:
my_list = ['hello', 'world', 'python']
for string in my_list:
print(string.upper())
输出结果为:
HELLO
WORLD
PYTHON
原文地址: https://www.cveoy.top/t/topic/biYH 著作权归作者所有。请勿转载和采集!