Created
July 2, 2021 11:13
-
-
Save RDCH106/7c55ff4ad3cc77c156d5f0e514e5a2f6 to your computer and use it in GitHub Desktop.
Revisions
-
RDCH106 created this gist
Jul 2, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- def classic_function(x, y ,z): print(x, y, z) def force_named_arguments_function(*, x, y ,z): print(x, y, z) if __name__ == "__main__": print("Classic function calling") print("================================================\n") classic_function(1, 2, 3) classic_function(1, 2, z=3) classic_function(x=1, y=2, z=3) try: eval('classic_function(x=1, 2, 3)') except SyntaxError as e: print(e) print("Expected error: classic_function(x=1, 2, 3)") # -------------------- print("\nFunction calling with required named arguments") print("================================================\n") try: eval('force_named_arguments_function(x=1, 2, 3)') except SyntaxError as e: print(e) print("Expected error: force_named_arguments_function(x=1, 2, 3)") try: eval('force_named_arguments_function(1, 2, z=3)') except TypeError as e: print(e) print("Expected error: force_named_arguments_function(1, 2, z=3)") force_named_arguments_function(x=1, y=2, z=3) try: eval('force_named_arguments_function(x=1, 2, 3)') except SyntaxError as e: print(e) print("Expected error: force_named_arguments_function(x=1, 2, 3)")