👨‍💻 dev lambda skill experiment

development

fukurou

the supreme coder
ADMIN
Python:
def process_text(text):
    text = text.strip()  # Remove whitespace
    text = text.upper()  # Convert to uppercase
    return f"Processed: {text}"

result = apply_function(process_text, "  hello world  ")
print(result)  # Output: "Processed: HELLO WORLD"
 

fukurou

the supreme coder
ADMIN
Python:
class Robot:
    def greet(self):
        return "Hello, I am a robot."

Python:
# Define a new function
def new_greet():
    return "Hi! I'm your waifubot!"

# Change the method dynamically
robot_instance = Robot()
robot_instance.greet = new_greet

print(robot_instance.greet())  # Output: "Hi! I'm your waifubot!"
 

fukurou

the supreme coder
ADMIN
Python:
class CustomBot:
    def __init__(self, action_func):
        self.action = action_func  # Set function dynamically

    def perform_action(self, *args):
        return self.action(*args)  # Call the function with arguments

# Define a custom function
def greet(name):
    return f"Hello, {name}!"

# Create an instance with a function passed in
bot = CustomBot(greet)
print(bot.perform_action("Alice"))  # Output: "Hello, Alice!"
 

fukurou

the supreme coder
ADMIN
Python:
def create_and_use_global():
    global counter  # Declare the variable as global
    if "counter" not in globals():  # Check if it exists first
        counter = 0  # Initialize only once
        print(f"Counter created: {counter}")
    else:
        counter += 1  # Modify the existing global variable
        print(f"Counter updated: {counter}")

create_and_use_global()
create_and_use_global()
create_and_use_global()

print(f"Final counter value: {counter}")  # Output: 2
 
Top