Which keyword is used to create a function in Python?

Study for the WGU C173 Scripting and Programming Test. Dive into coding challenges and multiple-choice questions with expert explanations. Prepare thoroughly and excel!

In Python, the keyword that is used to create a function is "def." This keyword signals the start of a function definition. When you use "def," you provide the function name followed by parentheses, which might include parameters, and then a colon. After that, the function's code block begins on the next line, typically with an indentation.

For example, defining a simple function in Python would look like this:


def my_function():

print("Hello, World!")

This structure is critical in Python, as it clearly indicates that a new function is being defined and helps maintain the clarity and readability of the code. Other languages may have their own specific keywords for defining functions, but in Python, "def" is the standard and accepted way to do so.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy