私は一連のチュートリアルを見てpython3を学んで
います。オプションの関数の引数()に関するこれらのビデオの1つで*args
、インストラクターはforループを使用して関数(タプル)に渡されるオプションのパラメーターを出力します。
インストラクターのスクリプトを実行しようとすると、エラーが発生します。
インストラクターのスクリプト:
def test(a,b,c,*args):
print (a,b,c)
for n in args:
print(n, end=' ')
test('aa','bb','cc',1,2,3,4)
出力:
C:\Python33\python.exe C:/untitled/0506.py
Traceback (most recent call last):
File "C:/untitled/0506.py", line 4, in <module>
for n in args: print(n, end=' ')
NameError: name 'args' is not defined
Process finished with exit code 1
def test(a,b,c,*args):
print (a,b,c)
print (args)
test('aa','bb','cc',1,2,3,4)
出力:
aa bb cc
(1, 2, 3, 4)
Process finished with exit code 0
エラーの原因は何ですか?
PS:私はPython3.3.0を使用しています。