Initializing Core...
Initializing Core...
Operational
Functions let you organize code into reusable blocks.
We define a function in Python with the use of def(). Below is an example.
def greet():print("Hello, welcome to Python!")greet()
We pass parameters and arguments through functions like in the example below.
def add(a, b):return a + bresult = add(10, 5)print(result) # 15
def greet_user(name="Guest"):print(f"Hello, {name}!")greet_user() # Hello, Guest!greet_user("Zarine") # Hello, Zarine!
def student_info(name, branch, year):print(f"{name} studies {branch} in year {year}")student_info(branch="ECE", year=2, name="Zarine")
def add_all(*nums):return sum(nums)print(add_all(1, 2, 3, 4)) # 10
square = lambda x: x * xprint(square(5)) # 25