<p>在print语句中打印汽车的价格,执行时会出现如下错误</p>
<blockquote>
<p>only strings can be concatenated in print stement</p>
</blockquote>
<pre><code>class Board:
def __init__(x1,car,price):
x1.car=car
x1.price=price
def init1(x1):
print("They brought a car "+x1.car +"for rupees" x1.price) ### this is where I need the print of price .
y=Board("xylo",2000)
y.init1()
</code></pre>
<p>他们花了2000卢比买了一辆木车,预计将投入生产。你知道吗</p>
<p>如果您使用的是python3.6+,那么可以使用<code>f-string</code>。你知道吗</p>
<pre class="lang-py prettyprint-override"><code>print(f"They brought a car {x1.car} for rupees {x1.price}")
</code></pre>