python为什么跳过我的函数?
当我输入这个时:python为什么跳过我的函数?,python,Python,当我输入这个时: def tablesUsed(): "Return which multiplication tables to use" tablesUsed = [int(x) for x in input("Please choose which multiplication tables you wish\nto practice, then type them like this: 2 5 10.\n").split()] python将函数跳过到下一行。发生了
def tablesUsed():
"Return which multiplication tables to use"
tablesUsed = [int(x) for x in input("Please choose which multiplication tables you wish\nto practice, then type them like this: 2 5 10.\n").split()]
python将函数跳过到下一行。发生了什么事?你需要打电话给它
tablesUsed()
您可能还希望实际返回列表
def tablesUsed():
return [int(x) for x in input("Please choose which multiplication tables you wish\nto practice, then type them like this: 2 5 10.\n").split()]
否则,您将无法访问在函数中创建的列表,使其变得无用
另外,如果您使用的是Python 2,
input()
将输入作为Python代码进行计算,很可能会出现错误。使用raw\u input()
返回字符串。在Python3中,raw_input()
被删除并替换为input()
似乎您只是在定义它,要使它运行,您需要调用它。Volatility
回答了您的问题,但不是input()
使用raw_input()
@GrijeshChauhan,OP可能正在使用Python3(尽管您确实不知道)