Python
Tooling
uv (https://github.com/astral-sh/uv)
An extremely fast Python package and project manager, written in Rust.
A single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more.
Syntax
Different types of methods
class Example:
def __init__(self, value):
self.value = value
def instance_method(self):
print(f"Instance method, self.value = {self.value}")
@classmethod
def class_method(cls):
print(f"Class method, cls = {cls.__name__}")
@staticmethod
def static_method():
print("Static method (no self or cls)")
e = Example(42)
e.instance_method() # Bound to instance
Example.class_method() # Bound to class
Example.static_method() # No binding
Type
Decorator
First Parameter
Used For
Instance
(none)
self
Behavior tied to object instance
Class Method
@classmethod
cls
Behavior tied to class (like factories)
Static Method
@staticmethod
none
Utility functions not tied to class/instance
Import
use import paths, not filenames (e.g. pandas.calculator) to avoid module name collisions
from X (X is actually a file name)
use alias
as Xin case you have the same class names
__name__
πΉ person.py
person.pyπΉ main.py
main.pyOutput:
Output:
__init.py__
Last updated
Was this helpful?