Python Function
๐ท Python Function – Notes (Very Easy Hinglish)
๐ธ Function kya hota hai?
Function ek code ka group hota hai jisko baar-baar use kar sakte hain bina baar-baar likhe.
๐ธ Syntax of Function:
def function_name():
# yeh kaam karega jab function call hoga
๐ธ Example:
def greet():
print("Hello! Welcome to Python.")
greet() # function ko call kiya
๐ข Output:
Hello! Welcome to Python.
๐ธ Function with Parameters:
def add(a, b):
print("Sum is:", a + b)
add(3, 4)
๐ข Output:
Sum is: 7
๐ธ Function with Return Value:
def square(x):
return x * x
result = square(5)
print("Square is:", result)
๐ข Output:
Square is: 25
๐จ Practice Exercises with Solution
✅ Exercise 1:
Q. Ek function banao jo "Good Morning" print kare.
def wish():
print("Good Morning!")
wish()
✅ Exercise 2:
Q. Ek function banao jo 2 numbers ka sum return kare.
def sum_two_numbers(a, b):
return a + b
print("Total:", sum_two_numbers(10, 20))
✅ Exercise 3:
Q. Ek function likho jo kisi number ka cube return kare.
def cube(n):
return n * n * n
print("Cube is:", cube(3))
✅ Exercise 4:
Q. Ek function likho jo diya gaya naam print kare:
def say_hello(name):
print("Hello", name)
say_hello("Navghan")
เค เคเคฐ เคเคช เคाเคนो เคคो เคฎैं aur difficult questions ya test-style questions bhi de sakta hoon. Batao?
Comments
Post a Comment