我想在列表的每个元素前面打印一个字符串,然后在新行中打印:
例子:
test = ["aaa", "bee", "cee"]
print("hello, %s" % "\n".join(storageVolume))
我从中得到的是:
hello, aaa
bee
cee
我想要的是:
hello, aaa
hello, bee
hello, cee
任何帮助表示赞赏。
我想在列表的每个元素前面打印一个字符串,然后在新行中打印:
例子:
test = ["aaa", "bee", "cee"]
print("hello, %s" % "\n".join(storageVolume))
我从中得到的是:
hello, aaa
bee
cee
我想要的是:
hello, aaa
hello, bee
hello, cee
任何帮助表示赞赏。
for x in test:
print "Hello, {0}".format(x)
In [10]: test = ["aaa", "bee", "cee"]
In [11]: print "\n".join("hello, "+x for x in test)
hello, aaa
hello, bee
hello, cee
或者:
In [13]: print "\n".join("hello, {0}".format(x) for x in test)
hello, aaa
hello, bee
hello, cee
In [51]: test = ["aaa", "bee", "cee"]
In [52]: for elem in test:
....: print "hello,", elem
....:
hello, aaa
hello, bee
hello, cee
for i in range(len(test)):
print "Hello, "+(test[i]);