リストの各要素の前に文字列を出力し、それを新しい行に出力したい:
例:
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]);