通常、次のコードを使用して、文字列内の変数を実装できます
print "this is a test %s" % (test)
ただし、これを使用する必要があったため、機能していないようです
from __future__ import print_function
通常、次のコードを使用して、文字列内の変数を実装できます
print "this is a test %s" % (test)
ただし、これを使用する必要があったため、機能していないようです
from __future__ import print_function
>>> test = '!'
>>> print "this is a test %s" % (test)
this is a test !
If you import print_function
feature, print
acts as function:
>>> from __future__ import print_function
>>> print "this is a test %s" % (test)
File "<stdin>", line 1
print "this is a test %s" % (test)
^
SyntaxError: invalid syntax
You should use function call form after the import.
>>> print("this is a test %s" % (test))
this is a test !
SIDE NOTE
According to the documentation:
str.format
is new standard in Python 3, and should be preferred to the%
formatting.
>>> print("this is a test {}".format(test))
this is a test !
これを試して:
print("this is a test", test)
またはこれ:
print("this is a test {}".format(test))
文字列を実装している場合は、%s
.