Python Environment and Colab Workflow
This page covers the first workflow patterns: executing Python, checking the runtime, using loops, storing dictionaries, and mounting Drive in Colab.
What you should be able to do
- Run simple Python statements and see returned values.
- Use a loop and an accumulator variable.
- Mount Google Drive when code needs external files.
Reusable patterns
- A notebook cell displays the value of the last expression.
- Use print() when you need guaranteed visible output.
- Colab-specific commands work in Colab, but may need changes in plain VS Code.
Python environment and Colab workflow
Listing 1. Basic arithmetic with variables
a = 10
b = 20
a + bExpected text output or note
30Listing 2. Check the Python version
!python --versionExpected text output or note
Python 3.12.13Listing 3. Code listing 3
total = 0
for i in range (1, 6):
total += i
print (total)Expected text output or note
15Listing 4. Code listing 4
loaded_dict = {"a": 1, "b": 2}
print (loaded_dict)Expected text output or note
{'a': 1, 'b': 2}Listing 5. Code listing 5
from google.colab import drive
drive.mount("/content/drive")Expected text output or note
Mounted at /content/drive