This is great because since you can use it at runtime, you can add checks in your code to behave differently depending on the version of Python you are using.
Here's how you can add an upgrade message if the user is not using the Python version you require:
PYTHON
import sys
if sys.version_info < (3, 10):
print("You need to upgrade to Python 3.10 or greater to use this program.")
sys.exit(1)
Conclusion
In this post, we learned how to check your version of Python using the command line and at runtime.
Checking at runtime is useful because it allows your program to tell the user to upgrade if they are using an older version of Python.
Hopefully, this has been useful for you. Thanks for reading!
To learn more about web development, founding a start-up, and bootstrapping a SaaS, follow me on X!