Fundamental
String
replace
text = "/uploads/file.png /uploads/file1.png"
text.replace("/uploads/", "https://example.com/uploads/")
# Output: "https://example.com/uploads/file.png https://example.com/uploads/file1.png"
Decorator
decorator biasanya digunakan untuk proses untuk authetication, log ataupun untuk timing function
# Decorator example
def my_decorator(func):
def wrapper():
print("Something before the function.")
func()
print("Something after the function.")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
# Annotation example
def greet(name: str) -> str:
return f"Hello, {name}