To check the Python version in your shell, you can use the following alternatives (aliases):
Terminal: The following commands can be used to check the Python version in your terminal. Note that the first and second are aliases whereas the third one provides more information about the built.
Note that you can also use the short-hand
py command to check the Python version in your terminal:
To learn about the difference between “
py” and “
python” commands, check out this article on the Finxter blog.
Script: You can also check the Python version in your Python script.
You can import the
sys library and call the
sys.version attribute to obtain a string representation of your Python version.:
import sys print(sys.version) # 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]
Even simpler, you can also just check the IDLE code editor for basic version information:
You can also obtain the version info in a tuple by using the following alternative:
import sys print(sys.version_info) # sys.version_info(major=3, minor=9, micro=5, releaselevel='final', serial=0)
An alternative is to use the following
import platform print(platform.python_version()) # 3.9.5
And if you need the version info in a tuple, use the following alternative:
import platform print(platform.python_version_tuple()) # ('3', '9', '5')
You can learn more about checking your Python version on the in-depth Finxter tutorial.
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.