Python Tutorial - Functions

Unlock Premium Features: AI explanations (Hinglish), Indian voice & Videos
Sign Up Free

โš™๏ธ Functions - Apna Code Robot Banao

๐ŸŒŸ Real Life Mein:

Reusable tasks har jagah hain:

๐Ÿณ "Recipe" - Same steps repeat, alag ingredients
๐Ÿญ "Factory machine" - Input do, output milta hai
๐Ÿงฎ "Calculator" - Numbers do, answer milta hai
๐Ÿค– "Coffee machine" - Button press, coffee ready

Function = Ek baar likho, baar-baar use karo!

๐ŸŽฏ Function Kyu Zaroori Hai?

Functions ke fayde:

  • Code reuse kar sakte ho
  • Code organized rahta hai
  • Testing aur debugging easy
  • Ek jagah change karo, har jagah update!
Simple Function
# Function define karo
def greet():
    print("Hello!")
    print("Welcome to Python!")

# Function call karo
greet()  # Output dono lines
greet()  # Dobara use kar sakte ho!

๐Ÿ“ฅ Parameters - Input Lena

๐ŸŽ‚ Birthday Greeting Generator
def birthday_wish(name, age):
    print(f"Happy Birthday {name}!")
    print(f"Aaj tum {age} saal ke ho gaye!")
    print("Party karo! ๐ŸŽ‰")

# Different people ke liye use karo
birthday_wish("Rohan", 15)
birthday_wish("Simran", 14)
birthday_wish("Amit", 16)

๐Ÿ“ค Return - Output Dena

๐Ÿงฎ Calculator Functions
def add(a, b):
    result = a + b
    return result

def calculate_bill(price, quantity, tax_percent):
    subtotal = price * quantity
    tax = subtotal * (tax_percent / 100)
    total = subtotal + tax
    return total

# Use karo
sum_result = add(10, 20)
print(sum_result)  # 30

bill = calculate_bill(100, 3, 18)
print(f"Total bill: โ‚น{bill}")
Function vs Method:
Function: len(list) - Independent
Method: list.append() - Object se attached

๐Ÿค– AI Tutor Unlock Karo!

Apni language mein coding seekho - Hindi, Marathi, Gujarati aur 10+ Indian languages mein!

  • Hinglish mein explanations
  • Real-life examples
  • Beginner-friendly
Free Signup Karo

Example

def hello():
    print("Hi")
hello()