- 3funtion
import math
def area_of_circle(radius):
area = math.pi * radius ** 2
return area
- funtion
def greet(name):
print(f"Hello, {name}!")
- funtion
add = lambda x, y: x + y
result = add(3, 4)
print(result)
import math
x = 16
sqrt_x = math.sqrt(x)
print(sqrt_x)
- 4funtion
add = lambda x, y: x + y
result = add(3, 4)
print(result)
import time
def timer(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(f"Time taken: {end_time - start_time:.2f} seconds")
return result
return wrapper
@timer
def slow_function():
time.sleep(2)
slow_function()
- 5funtion
people = [
{"name": "Alice", "age": 25},
{"name": "Bob", "age": 30},
{"name": "Charlie", "age": 20},
]
sorted_people = sorted(people, key=lambda x: x["age"])
print(sorted_people)
import time
def timer(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(f"Time taken: {end_time - start_time:.2f} seconds")
return result
return wrapper
@timer
def slow_function():
time.sleep(2)
slow_function()
- funtion
- funtion
- funtion
import math
def area_of_circle(radius):
area = math.pi * radius ** 2
return area
No comments