我是 Python 新手,正在通过 Kaggle 教程进行学习。在其中一个函数部分中,我正在输入这段代码。
def least_difference(a, b, c):
"""
Return the smallest difference between any two numbers among a, b, & c
"""
diff1 = abs(a - b)
diff2 = abs(b - c)
diff3 = abs(a - c)
return min(diff1, diff2, diff3)
print(
least_difference( 2, 200, 100 ),
least_difference( 1, 10, 10 ),
least_difference(5, 6, 7),
)
本教程是关于使用帮助功能的。所以当我打字时
>>> help(least_difference)
我收到错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'least_difference' is not defined
我在这里做错了什么?我是否缺少某些内容来查看文档字符串?
您需要将文件加载到交互式上下文中。用途:
$ python -i ./relative/path/to/file.py # or python3 depending on your PATH
...
>>> help(least_difference)
Return the smallest difference between any two numbers among a, b, & c
或者,直接从 REPL 导入:
$ python # or python3 depending on your PATH
...
>>> import ./relative/path/to/file.py
>>> help(least_difference)
Return the smallest difference between any two numbers among a, b, & c
NameError Traceback(最近一次调用最后一次)
在
名称错误:名称“http”未定义
请帮我查一下