Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这似乎是一个愚蠢的问题,但是如何在 easygui 上打印变量?
这是我的代码:
import easygui as eg a = 4 eg.msgbox(msg='Hello World',a)
错误是:
SyntaxError: non-keyword arg after keyword arg
我知道为什么会出现错误,因为 eg.codebox 期待title = "titleGoesHere"
title = "titleGoesHere"
任何人都知道如何在easygui中让变量显示在您的字符串旁边?
非常感谢。
如果您希望在a之后显示变量的内容Hello World,请尝试以下操作:
a
Hello World
import easygui as eg a = 4 eg.msgbox(msg='Hello World '+str(a))
在 Python 中,+符号连接字符串 (so 'a'+'bc'='abc'),但由于a具有整数值,我们调用str将转换4为 a的函数,'4'以便+将接收两个字符串:)
+
'a'+'bc'='abc'
str
4
'4'