为什么python跳过我的函数?

2024-04-20 12:45:57 发布

您现在位置: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跳过函数到下一行。怎么回事?在


Tags: toinyouwhichforinputtablesreturn
1条回答
网友
1楼 · 发布于 2024-04-20 12:45:57

你得给它打电话。在

tablesUsed()

您可能还想实际返回列表。在

^{pr2}$

否则,您将无法访问在函数中创建的列表,使其变得无用。在

另外,如果您使用的是python2,input()将输入作为Python代码进行计算,您很可能会得到一个错误。使用raw_input()返回字符串。在Python 3中,raw_input()被删除并被input()替换

相关问题 更多 >