🐍 Python Functions for Beginners

📚 Table of Contents

  • What is a Function?
  • Why Use Functions?
  • Creating a Function
  • Calling a Function
  • Function Parameters
  • Return Statement
  • Lambda Function
  • Practice Examples
  • FAQ

💡 Quick Tip

Functions help you write reusable code and make programs easier to understand.

⚠️ Common Mistakes

  • Forgetting parentheses while calling functions.
  • Wrong indentation inside function.
  • Not using return when output is needed.

✍️ By Roshni Code Charm

📅 July 2026 | ⏱️ 6 min read

🐍 What is a Function?

A function is a block of reusable code that performs a specific task. Functions help avoid writing the same code again and again.

⭐ Why Use Functions?

🛠️ Creating a Function

In Python, we create a function using the def keyword.


def greeting():
    print("Hello Python")

📞 Calling a Function

A function runs only when it is called.


def greeting():
    print("Hello Python")

greeting()

📦 Function Parameters

Parameters allow us to pass information into a function.


def greet(name):

    print("Hello", name)


greet("Roshni")

🔙 Return Statement

The return statement sends a value back from a function.


def add(a,b):

    return a+b


result = add(5,3)

print(result)

⚡ Lambda Function

Lambda is a small anonymous function written in one line.


square = lambda x: x*x

print(square(5))

🚀 Practice Examples

❓ Frequently Asked Questions

1. What is the use of functions in Python?

Functions make code reusable and organized.

2. Which keyword is used to create a function?

The def keyword is used to create functions.

3. What is a lambda function?

A lambda function is a small function without a name.