Defining and Calling Functions
Defining and Calling Functions. You might run into invalid syntax in Python when you’re defining or calling functions. For example, you’ll see a
SyntaxError if you use a semicolon instead of a colon at the end of a function definition, as seen here.
00:18 The traceback here is very helpful, with the caret pointing right to the problem character. You can quickly clear up this invalid syntax by switching out the semicolon for a colon. Speaking personally, my most common error is omitting the colon completely,
00:39 which generates the same problem and is quickly fixed. In addition, keyword arguments in both function definitions and function calls need to be in the right order.
Keyword arguments always come after positional arguments. Failure to use this ordering will lead to a
01:08 Once again, the error message is very helpful in telling you exactly what is wrong with the line.
Become a Member to join the conversation.