As of 2021, which python version is Google Colab using?

Python Googlecolab Featuredimage

As of 2021, one burning question lingered in the minds of many: “Which Python version is Google Colab using?” Let’s understand what version they’re using and what made them choose that version.

Also Read: 3 Approaches to Import .py Files in Google Colab

Which Python Version is used now in Google Colab?

Python is known for its simplicity and versatility, though the language does evolve over time. In 2021, Google Colab standardized on Python 3.x, moving away from the older Python 2.x. This reflects Python’s shifting landscape.

The version of Python used in Colab today is 3.10.12. This latest release brings helpful new features like the match statement for more expressive code. It also offers efficiency gains through bug fixes and enhancements. With its emphasis on clean, readable code, Python 3.10 furthers the language’s core values. The new version is expected out by April 2023.

You can check the version by typing the following snippet in Google Colab.

!python --version

Press the run button on the left and you will see the version running.

Check_Python_Version
Check_Python_Version

What Drove Google Colab’s Shift to Python 3?

Google Colab uses Python 3.x because Python 3.x offers certain advantages over previous versions. Improvements like type hints, data classes, and various optimizations made Python 3.7.x a stable option for Colab in early 2021. Python 3.8 and Python 3.9 later came into the picture, balancing performance gains with compatibility.

Python 3.10 actively builds on the foundations laid by Python 3.9. Compared to Python 3.8 and 3.7, the Python developers have introduced modern features in Python 3.10 that align with the evolving needs of the community. The language continues to mature in expressiveness and support for type hinting, providing developers with a more robust and feature-rich environment.

Also Read: How to Load Data From Google BigQuery Returning a Data Frame?

What Performance Improvements Does Python 3.10 Bring?

Open Google Colab, and let’s explore Python 3.10 together.

Pattern Matching

Python 3.10 introduced the powerful match statement, revolutionizing the way developers handle complex conditional statements. This addition enhances code readability and expressiveness, setting Python 3.10 apart from its predecessors.

value = 3
match value:
    case 1:
        print("It's one")
    case 2 | 3:
        print("It's two or three")
    case _:
        print("It's something else")

Execute this code snippet in a Python 3.10 Colab environment as follows.

Match_Keyword_in_python
Match_Keyword_in_python

Case 3 satisfies and the resulting statement “It’s two or three” is printed.

Precise Types with TypeGuard

Building on the foundation of Python 3.9, Python 3.10 allows for parentheses in context managers, enabling a more concise and readable organization of multiple context managers in a single with statement.
from typing import Any, TypeGuard

def is_string(value: Any) -> TypeGuard[str]:
    return isinstance(value, str)

Execute this code snippet in a Python 3.10 Colab environment as follows.

TypeGuard in Python
TypeGuard in Python

The code successfully runs as shown.

Performance Improvements

Each Python version brings performance optimizations, and Python 3.10 is no exception. While the improvements may not always be explicitly visible, they collectively enhance the overall efficiency of the language.

Which Python Version Is Better 3.10 or 3.9?

As of now 3.10 is the most upgraded version used and thus it comes with modern advancements, but unlike other versions, it depends on the project’s uses to know which version suits the best.

Why did Colab switch to Python 3 from Python 2?

Colab upgraded to Python 3 to provide access to the latest features and optimizations of Python. The Python 3 line has become the standard for new Python development.

Do I have to update my Python code to run on Colab?

No – one of Colab’s advantages is it allows you to seamlessly switch between Python versions, including Python 2.7. So older code will still work. Upgrading can provide access to the latest features though.

Summary

Google Colab has upgraded to using Python 3.x as its standard version. This keeps Colab current as Python continues evolving as a language. Back in 2021, Colab switched over from Python 2.x to start using Python 3.7. This offered helpful new features while maintaining stability.

Today, Colab runs the latest major release – Python 3.10. So what does this newest 3.10 upgrade provide? Some nice new additions to write cleaner code, like the match statement for conditional logic. Also continual performance boosts with each new version through optimization.

At the same time, Colab allows switching between versions easily. This flexibility lets developers use whatever Python flavor makes the most sense for their projects.

References

https://stackoverflow.com/questions/65912429/as-of-2021-which-python-version-is-google-colab-using

https://colab.google/articles/py3.10