Bird
0
0

Which of the following is the correct syntax to define a function in procedural Python code?

easy📝 Syntax Q3 of 15
Python - Object-Oriented Programming Foundations
Which of the following is the correct syntax to define a function in procedural Python code?
Aclass my_function():
Bdef my_function():
Cfunction my_function():
Ddef my_function[]:
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python function syntax

    Functions in Python are defined using the keyword 'def' followed by the function name and parentheses.
  2. Step 2: Check each option

    def my_function(): matches correct syntax. class my_function(): defines a class, not a function. function my_function(): uses wrong keyword. def my_function[]: has invalid brackets.
  3. Final Answer:

    def my_function(): -> Option B
  4. Quick Check:

    Function syntax = def name(): [OK]
Quick Trick: Functions start with 'def' keyword [OK]
Common Mistakes:
  • Using 'class' instead of 'def' for functions
  • Incorrect brackets or missing colon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes