2024-10-02 02:36:38 发布
网友
下面是我正在开发的tikinter应用程序的代码片段
stringGreet = "Hello Employee"+myresults[0],myresults[1]+"who is"+myresults[2] managerGreeting.set(stringGreet) raiseFrame(managerMenuFrame)
为什么这段代码会导致串接的字符串被大括号环绕? 结果不正确
结果正确
Hello Employee Joe Smalls who is Male
您将元组输入到managerGreeting.set(stringGreet),因为您创建了一个元组:
managerGreeting.set(stringGreet)
stringGreet = "Hello Employee"+myresults[0] , myresults[1]+"who is"+myresults[2]
创建单个字符串:
stringGreet = "Hello Employee {},{} who is {}".format(myresults[0],myresults[1],myresults[3])
你也可以使用
stringGreet = "Hello Employee {},{} who is {}".format(*myresults[:3])
相反。如果myresults只包含3个元素,请删除[:3]
myresults
[:3]
如果逗号不正确,请考虑使用f-string
stringGreet = f"Hello Employee {myresults[0]} {myresults[1]} who is {myresults[2]}"
您将元组输入到
managerGreeting.set(stringGreet)
,因为您创建了一个元组:创建单个字符串:
你也可以使用
相反。如果
myresults
只包含3个元素,请删除[:3]
如果逗号不正确,请考虑使用f-string
相关问题 更多 >
编程相关推荐