如何将字符串和变量插入打印语句中?
我正在尝试编程一些将显示我在打印语句中写的变量的内容,但是每当我运行代码时,它都不会显示变量,它只是说“无”。
我的代码:
sidewalkclosed = True
raining = True
xPos = 400
yPos = 400
print("Your robot is located at",print(yPos),"on the y axis and",print(xPos),"on the x
axis.")
I am trying to program something that will display the variable that I wrote earlier in a print statement but whenever I run the code it doesn't display the variable, it just says "None".
My code:
sidewalkclosed = True
raining = True
xPos = 400
yPos = 400
print("Your robot is located at",print(yPos),"on the y axis and",print(xPos),"on the x
axis.")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试一下。
错误
,您没有得到,而不是400和400,这是因为打印功能返回无。
执行您的代码。
从代码中输出
当打印函数读取他获得的输入时,在此代码中
print(ypos)
和print(xpos)
他运行了这两个打印功能,并且捕获返回值
无
。Try this.
ERROR
Here you got None Instead of 400 and 400 this is because the print function returns None.
Execution Of Your Code.
OUTPUT From Your Code
In this code when the print function read the input he got
print(yPos)
andprint(xPos)
He runs those two print functions andcapture the returning value Which is
None
.我建议使用F字符串 -
I would recommend using f strings -
由于某种原因,您已经将print()insral print()更改为
you have put print() inside print() for some reason just change it to