2024-06-16 09:40:23 发布
网友
我想在列表的每个元素前面打印一个字符串,然后在新行中打印:
示例:
test = ["aaa", "bee", "cee"] print("hello, %s" % "\n".join(storageVolume))
我从中得到的是:
我想要的是:
hello, aaa hello, bee hello, cee
感谢任何帮助。在
In [10]: test = ["aaa", "bee", "cee"] In [11]: print "\n".join("hello, "+x for x in test) hello, aaa hello, bee hello, cee
或者:
for x in test: print "Hello, {0}".format(x)
In [51]: test = ["aaa", "bee", "cee"] In [52]: for elem in test: ....: print "hello,", elem ....: hello, aaa hello, bee hello, cee
或者:
^{pr2}$相关问题 更多 >
编程相关推荐