__version__ — Easy Examples
Convention for storing a package or module's version string
Accessing __version__
How to access and use __version__.
python
# __version__ holds package version info import sys print(sys.version) print(sys.version_info) # Many packages define __version__ import json print(hasattr(json, "__version__"))
__version__ is a special attribute that convention for storing a package or module's version string.
__version__ in practice
Using __version__ in everyday code.
python
# More __version__ examples print("__version__ is a special Python attribute") # Every object has certain dunder attributes obj = object() attrs = [a for a in dir(obj) if a.startswith("__")] print(f"object has {len(attrs)} dunder attributes")
Understanding __version__ helps you introspect and debug Python objects.
Want to try these examples interactively?
Open Easy Playground