Example of use Prism:
# Your Python code goes here
from types import MethodType
class Person:
def __init__(self, name):
self.name = name
# Function to add dynamically as a method
def say_hello(self):
return f"Hello, my name is {self.name}"
# Create an instance of Person
person = Person("Alice")# Bind the function say_hello to person instance as a method
person.say_hello = MethodType(say_hello, person)
# Call the new method on the instance
print(person.say_hello()) # Output: "Hello, my name is Alice"
https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism-tomorrow.min.css https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/components/prism-python.min.js
Немає коментарів:
Дописати коментар