我有一个变量,它可以是单个字符串或字符串列表。当变量是单个字符串时,循环按字符迭代它。
text = function() # the function method can return a single string or list of string
for word in text:
print word+"/n"
# When it is a single string , it prints char by char.
当字符串只有一个时,我希望循环只迭代一次。我实际上不想使用其他类型的循环。如何使用 for each 结构来实现?
text
的类型怎么样? - Mohammad