Python Learning Series · @onlysamarrr · Day 14 / 30

Day 14: Functions

Day 14 teaches functions. def creates a reusable block of code, parameters are its inputs, and return sends a value back. print only shows something; it does not return it.

Phase: Beginner · Reels: 66/450 – 70/450

Quick Answer

Day 14 teaches functions. def creates a reusable block of code, parameters are its inputs, and return sends a value back. print only shows something; it does not return it.

What You Will Learn

Code

def square(n):
    """Return the square of n"""
    return n * n

def greet(name):
    print("Hi", name)

print(square(4))
print(square(5))
result = greet("Arhan")
print(result)

Output

16
25
Hi Arhan
None

Code Explained, Line by Line

  1. def square(n): creates a function named square with one parameter, n.
  2. return n * n sends the answer back, so print(square(4)) shows 16.
  3. A function that only prints and never returns gives None when assigned to a variable.
  4. A docstring ("""...""") is a short note about what the function does.
  5. Functions matter because they reuse code (DRY), are easier to test, and make code readable by name.
Common Mistake: print is not return: print shows a value on screen, return gives it to the code that called the function. Confusing them is the most common function bug.

Real-Life Use

Every real app is built from functions: one for login, one for payment, one for sending email.

Practice Task: Write a square function, and a function that returns 'Hi, name' instead of printing it.

Test Yourself — MCQs

Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.

Q1. What does square(4) return if square returns n * n?

Q2. What does a function return if it only prints?

Q3. What keyword defines a function?

Today's 5 Reels (from the 90-Day Plan Excel)

66/450Conceptdef se function banao
67/450Live demoParameters aur return
68/450Common mistakeprint vs return
69/450QuizQuiz: square function
70/450Interview / real lifeInterview: function kyun zaroori
← Day 13Day 15 →