Functions ka Jadoo in Python ✨ | Return, Arguments, Scope & More #7 || Python ka Pitara || DeathCode - DeathCode

Python Series – Part 7: Functions in Python (Full Detailed Guide)


🧠 Objective:

  • Functions kya hote hain
  • Function syntax
  • Parameters, return value
  • Default arguments, *args, **kwargs
  • Functions ka real-world use

πŸŽ‰ Introduction

"Socho agar har baar tumhe ek hi code baar baar likhna pade…

Jaise ek chai banane ki recipe β€” har time same steps, same ingredients…

Toh har baar likhna bore nahi hoga?

Bas isi dikkat ka solution hai β€” Functions!

Aaj ke video me hum seekhenge Functions in Python β€” from basic to advanced level tak!

Let's gooooo!"


🧹 Section 1: What is a Function?

"Function ek block of code hota hai jo specific task perform karta hai.

Jaise ek machine β€” input do, processing kare, output de."

Example:

def greet():
    print("Hello, welcome to Python ka Pitara!")

"Is function ko jab call karoge, ye greeting dega."


❓ Section 2: Why Use Functions?

Without functions:

print("Chai ready hai")
print("Chini daali")
print("Doodh daala")

With function:

def make_tea():
    print("Chini daali")
    print("Doodh daala")
    print("Chai ready hai")
 
make_tea()

"Function se code reusable, organized aur error-free banta hai."


🧱 Section 3: Function Syntax

def function_name(parameters):
    # code block
    return something
  • def β†’ function banane ke liye
  • function_name β†’ meaningful naam
  • parameters β†’ inputs (optional)
  • return β†’ output (optional)

πŸ”„ Section 4: Types of Functions

  1. Without Parameters, Without Return
def say_hello():
    print("Hello")
  1. With Parameters, Without Return
def greet(name):
    print(f"Hello {name}")
  1. With Parameters, With Return
def add(a, b):
    return a + b

"Return ka matlab output lekar function se bahar nikalna."


🧠 Section 5: How Return Works

"Return se value milti hai aur function wahi ruk jaata hai."

Example:

def is_even(num):
    return num % 2 == 0

Important:

  • return ke baad ka code nahi chalta
  • Agar return nahi diya to None return hota hai

πŸ§™β€β™‚οΈ Section 6: Default Parameters, Keyword Arguments

Default Parameter:

def greet(name="Guest"):
    print(f"Hello {name}")

Keyword Arguments:

def intro(name, age):
    print(f"{name} is {age} years old.")
 
intro(age=25, name="Rahul")

"Keyword arguments me order matter nahi karta."


⚑ Section 7: *args and **kwargs

*args β†’ multiple positional arguments

def total(*numbers):
    return sum(numbers)
 
print(total(2, 3, 5))

**kwargs β†’ multiple keyword arguments

def info(**data):
    for key, value in data.items():
        print(f"{key} = {value}")
 
info(name="Aman", age=22)

"Dynamic inputs ke liye yeh bahut kaam aate hain."


πŸ” Section 8: Functions are First-Class Citizens

"Python me function ko variables me store, function ke andar pass ya return bhi kar sakte hain."

Example:

def greet():
    return "Hello"
 
msg = greet
print(msg())

πŸ“š Section 9: Real-World Examples

  • len(), sorted(), input(), print() β€” sab functions hi hain
  • Python libraries = functions ka collection

πŸ§ͺ Section 10: Practice Zone

Practice Questions:

  1. Write a function to calculate factorial.
  2. Write a function to reverse a string.
  3. Write a function to check prime number.
  4. Write a function to return sum of even numbers in a list.

πŸ§‘β€πŸŽ“ Outro

"Functions ka magic samajh aaya?

Ab agla part aur bhi deep jaane wala hai β€” Scope aur Execution Context (LEGB Rule)!

Channel ko subscribe karo, practice karo, aur comment me apna favourite concept likhna mat bhoolna! πŸš€"

Β© 2024 DeathCode. All Rights Reserved.