[英]Passing values out of functions in python
I am trying to get my head around python.我正在努力了解 python。 This is a snippet of code where I want to have the user input an option in a function and then use that input in another function(s).
这是一段代码,我想让用户在一个函数中输入一个选项,然后在另一个函数中使用该输入。 This tells me 'myInput' is not defined.
这告诉我“myInput”未定义。
def main():
myInput = input("Enter a number ")
# This is the main function that will be the primary executuable function - the start of the program
return(myInput)
if __name__ == '__main__':
main()
#
print (myInput)
Function main
returns the user's input, so try this:函数
main
返回用户的输入,所以试试这个:
if __name__ == '__main__':
myInput = main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.