私はPythonプログラマーの初心者ですが、独自の関数を定義して使用するスクリプトを含むいくつかのスクリプトを作成しました。IDLE 内でユーザー定義関数を動作させることができないようです。私は頭がおかしい/頭が悪いのだろうか。誰かが次の結果を説明できますか?ありがとう:
def f(x,y):
solution = x+y
return solution
f(2,2)
SyntaxError: invalid syntax
>>> a = f(2,2)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a = f(2,2)
NameError: name 'f' is not defined
def g(x):
solution = x + 2
return solution
g(2)
SyntaxError: invalid syntax
>>> a = g(2)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
a = g(2)
NameError: name 'g' is not defined