Defining & Calling Functions0%

Defining & Calling Functions

Beginner8 min readUpdated: 2026-09-03
Study Materials

Defining & Calling Functions

Functions are reusable blocks of code that execute only when invoked, eliminating repetitive logic.


Key Concepts & Detailed Explanation

undefined


Code Examples & Output

Python
# Defining a function
def greet_student(name, course="Python"):
print(f"Welcome, {name}! You are learning {course} at MSK Institute.")
 
# Calling the function
greet_student("Pooja")
greet_student("Aditya", "Full Stack Development")

Expected Output:

Output
Welcome, Pooja! You are learning Python at MSK Institute.
Welcome, Aditya! You are learning Full Stack Development at MSK Institute.

Best Practices & Common Pitfalls

Always define functions before the line of code that calls them; Python reads top to bottom.


Practice Quiz

1. Which keyword defines a function in Python?

  • A) function
  • B) fn
  • C) def
  • D) func
Answer: C Explanation: The 'def' keyword defines functions.

2. What naming style should be used for Python functions according to PEP 8?

  • A) camelCase
  • B) snake_case
  • C) PascalCase
  • D) UPPERCASE
Answer: B Explanation: PEP 8 prescribes snake_case for functions (e.g. calculate_total).

Practice Challenge

Write a function 'celsius_to_fahrenheit(c)' and test it with 0°C and 100°C.

Next Lesson

Arguments: Positional, Keyword

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 1 questions. Each question has one correct answer.

PrevNext