인수(argument)들에 관련된 오류들을 보고 수정해보자!
매개변수에 넘겨줄 값이 너무 많거나 개수가 정해지지 않았을 때 사용
1 2 3 4 5 6 | def func_param_with_var_args(name, *args, age): print("name=",end=""), print(name) print("args=",end=""), print(args) print("age=",end=""), print(age) func_param_with_var_args("정우성", "01012341234", "seoul", 20) | cs |
해결
문제에서는 name에 "정우성, 가변인자를 통해 "01012345678","seoul", age에 20을 넣으려고 하는 것 같다. 오류를 수정하면
1 2 3 4 5 6 | def func_param_with_var_args(name, *args, age): print("name=",end=""), print(name) print("args=",end=""), print(args) print("age=",end=""), print(age) func_param_with_var_args("정우성", "01012341234", "seoul", age = 20) | cs |
1 2 3 4 5 6 | def func_param_with_var_args(name, age ,*args): print("name=",end=""), print(name) print("args=",end=""), print(args) print("age=",end=""), print(age) func_param_with_var_args("정우성", 20 ,"01012341234", "seoul") | cs |
1 2 3 4 5 6 7 | def func_param_with_kwargs(name, age, **kwargs, address=0): print("name=",end=""), print(name) print("age=",end=""), print(age) print("kwargs=",end=""), print(kwargs) print("address=",end=""), print(address) func_param_with_kwargs("정우성", "20", mobile="01012341234", address="seoul") | cs |
1 2 3 4 5 6 7 | def func_param_with_kwargs(name, age, address=0, **kwargs): print("name=",end=""), print(name) print("age=",end=""), print(age) print("kwargs=",end=""), print(kwargs) print("address=",end=""), print(address) func_param_with_kwargs("정우성", "20", address="seoul", mobile="01012341234") | cs |
1 2 3 4 5 6 7 8 | def mixed_params(name="아이유", *args, age, **kwargs, address): print("name=",end=""), print(name) print("args=",end=""), print(args) print("age=",end=""), print(age) print("kwargs=",end=""), print(kwargs) print("address=",end=""), print(address) mixed_params(20, "정우성", "01012341234", "male" ,mobile="01012341234", address="seoul") | cs |
1 2 3 4 5 6 7 8 | def mixed_params(age, name="아이유", *args, address, **kwargs): print("name=",end=""), print(name) print("args=",end=""), print(args) print("age=",end=""), print(age) print("kwargs=",end=""), print(kwargs) print("address=",end=""), print(address) mixed_params(20, "정우성", "01012341234", "male" ,address="seoul", mobile="01012341234") | cs |