You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimizes memory usage by restricting dynamic attribute creation.
classStudent:
__slots__= ['name', 'age'] # Only these attributes can be assigneddef__init__(self, name, age):
self.name=nameself.age=ages=Student("John", 22)
# s.grade = "A" # This will raise an AttributeError
8. __package__
Indicates the package a module belongs to.
print(__package__) # Output: None (if run directly)
9. __cached__
Holds the path to the compiled .pyc file of the module.
importosprint(os.__cached__) # Example Output: '/usr/lib/python3.10/__pycache__/os.cpython-310.pyc'
10. __all__
Defines a list of public objects for from module import *.
# mymodule.py__all__= ['func1', 'func2']
deffunc1():
passdeffunc2():
passdeffunc3(): # Won't be imported with `from mymodule import *`pass
Advanced Special Variables
11. __import__
A built-in function used to import modules dynamically.