首页 > 解决方案 > 如何在 print() 字符串中嵌入变量,然后在 python 3.9 中调用函数

问题描述

我正在研究需要用户输入他们的名字的python代码,理论上它工作得很好,但是当我运行脚本时,我得到这3行作为输出:

Please Enter your name

Your name will be saved as,  <built-in function input>

这是代码:

# Function for the user's name and then sends user to menu
print("Please Enter your name\n")
name = input
print("Your name will be saved as, ", name,)
menu()

标签: python-3.xfunctionvariables

解决方案


线。名称=输入。保存什么是函数“输入”你需要以正确的方式使用函数“输入”

# Function for the user's name and then sends user to menu
print("Please Enter your name\n")
name = input()
print("Your name will be saved as, ", name,)
menu()

推荐阅读