Chapter 2: Getting started
The chapter introduces Google Colaboratory and the book’s GitHub code as a quick way to start running Python examples and lab exercises.
After this chapter you will be able to
- Colaboratory and book code. Explain why the chapter pairs Google Colaboratory with the book’s GitHub code: Colaboratory provides a web-hosted Python environment, and the repository provides code for each chapter to test examples and work through labs.
- Supported version choice. Explain why a supported Python version is suitable for this book, even if it is not the latest, and describe the support period.
- Python sources and installation choice. Describe where Python can be obtained and explain why the choice depends on your situation rather than having one required source.
- Python platform and implementation range. Describe the range of devices and environments where Python runs, and explain that the common C-based implementation is not the only way Python can run.
- Jupyter notebook interface. Explain how Jupyter notebooks combine executable code cells with Markdown-formatted text in a browser interface, and distinguish running a Jupyter server locally from using one hosted in the cloud.
- Reasons for using Colaboratory. Explain why the book recommends Google Colaboratory: it avoids local Python installation and updates, offers Jupyter’s friendly interface, and lets readers open the book’s GitHub notebooks in a browser on virtually any device.
- Finding the chapter notebook. Describe how to locate the chapter 2 notebook in the book’s GitHub repository, and explain what GitHub knowledge or access is needed.
- Opening the chapter notebook. Describe the two routes for opening Chapter_02.ipynb in Colaboratory: use GitHub’s Open in Colab link, or open Colaboratory directly and select the notebook from the book’s GitHub repository.
- Colaboratory convenience and version tradeoff. Explain that Colaboratory removes the need to install and maintain a Python environment and makes Jupyter notebooks accessible through a standard web browser, while its Python version may lack a few of the newest features.
- Text and code cells. Distinguish text cells, which hold Markdown-formatted text, from code cells, which hold executable code.
- Running code cell output. Describe how to run a code cell and where any resulting output appears.
- Hello World cell execution. Describe how the Hello, World example runs in the chapter 2 notebook: a code cell contains a call to print() with "Hello, World" as its argument, and Ctrl-Enter runs the cell and displays the output below it.
- Reading code cell errors. Explain where a Jupyter code-cell error appears and how Python identifies the location and nature of the missing-parenthesis error shown here.
- Two ways to use help. Explain how to use help() interactively or with a type or variable name to read Python documentation, and when the targeted form is more convenient.
- Namespace inspection with dir. Describe what dir() lists with no argument and what it can list when given a module or type, including why that is useful.
- AI code generation and judgment. Explain that large language model–based tools can generate working code from a text prompt, but their output is not always reliable and human understanding remains vital to good code.
- AI code generation benefits. Explain why AI code generation can save time and avoid some small coding mistakes.
- Review of generated code. Explain why AI-generated code needs careful review and testing before production use, even when it looks good.
- AI tool choice tradeoffs. Explain why Colaboratory’s AI code generator is the most convenient option for this book’s exercises, while Copilot may appeal more for production code.
Section by section
Introduction
The chapter introduces Google Colaboratory and the book’s GitHub code as a quick way to start running Python examples and lab exercises.
- Colaboratory and book code: Explain why the chapter pairs Google Colaboratory with the book’s GitHub code: Colaboratory provides a web-hosted Python environment, and the repository provides code for each chapter to test examples and work through labs.
Why it matters: This setup gives you a quick way to try the book’s code as you read.
Key terms: Google Colaboratory, GitHub repository, code examples, lab exercises
2.1 Paradox of choice: Which Python?
The section introduces the growing range of ways to run Python and previews a survey of the options before the book’s use of Google Colaboratory.
2.1.1 Python versions
This section explains Python’s annual release schedule and how to choose a version that will work with the book.
- Annual Python release cycle: Describe how Python’s release schedule changed and when new versions now come out.
Why it matters: The annual schedule explains why readers may encounter several recent Python versions. - Supported version choice: Explain why a supported Python version is suitable for this book, even if it is not the latest, and describe the support period.
Why it matters: You need not install the newest Python release to work through the book.
Key terms: annual release cycle, Python 3.9, supported version, full releases, security fixes
2.1.2 Sources of Python
This subsection identifies ways to obtain Python and explains why readers can postpone choosing a local installation.
- Python sources and installation choice: Describe where Python can be obtained and explain why the choice depends on your situation rather than having one required source.
Why it matters: You can start learning without first settling on a local Python installation.
Key terms: python.org, Anaconda, app store, package manager, source code, local install
2.1.3 Devices, platforms, and operating systems
Python runs across many kinds of devices and environments, with implementations that extend beyond the common C-based one.
- Python platform and implementation range: Describe the range of devices and environments where Python runs, and explain that the common C-based implementation is not the only way Python can run.
Why it matters: Python’s reach is broader than a single kind of computer or implementation.
Key terms: devices, operating systems, processors, implementation, C language, Java
2.1.4 Environments and tools
This section surveys ways to write and run Python code, then explains what Jupyter notebooks add to those options.
- Python development options: Describe the range of ways to write and run Python code, from a command-line interpreter and text editor to education-oriented and advanced IDEs.
Why it matters: You can choose a development tool that suits how you want to work. - Jupyter notebook interface: Explain how Jupyter notebooks combine executable code cells with Markdown-formatted text in a browser interface, and distinguish running a Jupyter server locally from using one hosted in the cloud.
Why it matters: This explains why notebooks are useful for presenting explanations alongside runnable code.
Key terms: Python interpreter, IPython, IDE, Jupyter, notebook, Markdown, code cells
2.2 Colaboratory: Jupyter notebooks in the cloud
This section recommends Google Colaboratory for working through the book and explains how the book presents its code.
- Reasons for using Colaboratory: Explain why the book recommends Google Colaboratory: it avoids local Python installation and updates, offers Jupyter’s friendly interface, and lets readers open the book’s GitHub notebooks in a browser on virtually any device.
Why it matters: These conveniences explain the book’s recommended way to get started with its code. - Book code presentation format: Describe the book’s default code format and its alternatives: examples and solutions are presented as Jupyter notebooks unless stated otherwise, but the code also works in other environments and is provided as text files.
Why it matters: Readers can follow the notebook examples without assuming they are tied to Colaboratory.
Key terms: Colaboratory, Jupyter notebooks, GitHub, text files
2.2.1 Getting the source notebooks
This section shows how to find the book’s chapter 2 notebook in its GitHub repository so you can get started with Colaboratory.
- Finding the chapter notebook: Describe how to locate the chapter 2 notebook in the book’s GitHub repository, and explain what GitHub knowledge or access is needed.
Why it matters: Finding the supplied notebook gives you a starting point for the book’s Colaboratory exercises.
Key terms: GitHub repository, code directory, Chapter 02, Chapter_02.ipynb
2.2.2 Getting started with Colaboratory
This section shows how to open the book’s chapter 2 notebook in Colaboratory and explains when a Google account is required.
- Opening the chapter notebook: Describe the two routes for opening Chapter_02.ipynb in Colaboratory: use GitHub’s Open in Colab link, or open Colaboratory directly and select the notebook from the book’s GitHub repository.
Why it matters: Either route gets you to the book’s code so you can try it in Colaboratory. - Google account requirement: Distinguish accessing Colaboratory without an account from logging in to run code and use all its features.
Why it matters: This distinction explains why opening a notebook and running or saving work have different requirements.
Key terms: Chapter_02.ipynb, Open in Colab, Open notebook, GitHub URL, Google account, Colaboratory, save sessions and files
2.2.3 Colaboratory’s Python version
This section explains why Colaboratory’s convenience outweighs the possibility that its Python version is slightly behind the latest release.
- Colaboratory convenience and version tradeoff: Explain that Colaboratory removes the need to install and maintain a Python environment and makes Jupyter notebooks accessible through a standard web browser, while its Python version may lack a few of the newest features.
Why it matters: You can decide whether Colaboratory’s convenience suits you while remembering that a very new Python feature might not be available.
Key terms: Colaboratory, Python environment, Jupyter notebooks, Python version
2.3 Writing and running code in Colaboratory
Explains how to edit text cells and run code cells in a Colaboratory notebook, including where output appears and when changes are saved.
- Text and code cells: Distinguish text cells, which hold Markdown-formatted text, from code cells, which hold executable code.
Why it matters: The cell type determines whether you are editing explanatory text or running code. - Editing notebook text: Describe how to enter and leave a text cell’s edit mode, and state the section’s limits on saving changes.
Why it matters: Editing a cell does not mean your changes will persist in Colaboratory or alter the source repository. - Running code cell output: Describe how to run a code cell and where any resulting output appears.
Why it matters: Running a cell and finding its output are the basic steps for trying code in a notebook.
Key terms: Jupyter notebook, text cells, code cells, Markdown, edit mode, text mode, source notebooks, GitHub repository, Google account, Ctrl-Enter
2.3.1 Hello, World
This subsection runs a Hello, World example in a Colaboratory code cell and explains how the book distinguishes entered code from output.
- Hello World cell execution: Describe how the Hello, World example runs in the chapter 2 notebook: a code cell contains a call to print() with "Hello, World" as its argument, and Ctrl-Enter runs the cell and displays the output below it.
Why it matters: This gives you a concrete way to run a Python command and recognize its result in a notebook. - Code and output typography: Distinguish entered code from its output in the book’s examples by the font weight used for each.
Why it matters: The formatting helps you tell what to enter from what Python displays.
Key terms: print(), code cell, Ctrl-Enter, output, normal-weight monospace, monospace bold
2.3.2 Dealing with errors in Jupyter
This section shows where Jupyter displays Python errors, how to read a simple syntax error, and why to review Colaboratory’s suggested fixes.
- Reading code cell errors: Explain where a Jupyter code-cell error appears and how Python identifies the location and nature of the missing-parenthesis error shown here.
Why it matters: The error display gives you a place to start looking when a code cell fails. - Reviewing suggested error fixes: Describe what Colaboratory’s Fix Error option may do and why its suggested change should be examined before acceptance.
Why it matters: An offered fix can save effort, but you still need to decide whether it is sound.
Key terms: code cell, error message, syntax error, caret, incomplete input, Colaboratory, Fix Error, suggested fix
2.4 Using help and dir to explore Python
This section shows how to explore Python’s built-in documentation with help() and inspect names with dir().
- Two ways to use help: Explain how to use help() interactively or with a type or variable name to read Python documentation, and when the targeted form is more convenient.
Why it matters: You can check an object’s behavior or a method’s exact syntax while you work. - Namespace inspection with dir: Describe what dir() lists with no argument and what it can list when given a module or type, including why that is useful.
Why it matters: It gives you a quick way to see what names and members are available.
Key terms: help(), help system, help> prompt, dir(), namespace, current global namespace, members
2.5 Using AI tools to write Python code
This section introduces AI code-generation tools as useful but unreliable aids that still require human understanding.
- AI code generation and judgment: Explain that large language model–based tools can generate working code from a text prompt, but their output is not always reliable and human understanding remains vital to good code.
Why it matters: It frames AI-generated code as something to evaluate, not simply accept.
Key terms: large language model–based tools, text prompt, AI-generated solutions, human understanding
2.5.1 Benefits of AI tools
This section explains two practical benefits of AI code generation: speed and fewer typing mistakes.
- AI code generation benefits: Explain why AI code generation can save time and avoid some small coding mistakes.
Why it matters: These benefits help you weigh when AI-generated code might be useful.
Key terms: AI code generation, prompt, chatbot
2.5.2 Negatives of using AI tools
This section explains the environmental, privacy, cost, and code-quality drawbacks to weigh before using AI-generated code.
- Review of generated code: Explain why AI-generated code needs careful review and testing before production use, even when it looks good.
Why it matters: Generated code can look convincing while hiding problems that matter in production. - Code sharing and protection: Describe the privacy and intellectual-property concern involved in using an AI bot for coding.
Why it matters: Code sharing can raise concerns even when the generated result is useful. - Resource use and pricing: Explain the resource and financial costs the section associates with AI coding tools.
Why it matters: The cost of using an AI coding tool includes more than the price shown to its user.
Key terms: AI-generated code, review and testing, bugs and inefficiencies, sharing your code, other’s code, privacy, intellectual property, energy and water, resources, free of charge
2.5.3 AI options
This section compares AI code-generation options for the book’s exercises and explains why using one is optional.
- AI tool choice tradeoffs: Explain why Colaboratory’s AI code generator is the most convenient option for this book’s exercises, while Copilot may appeal more for production code.
Why it matters: You can choose a tool based on the work you’re doing rather than assuming the book requires a particular setup. - Optional AI tool use: State why readers need not use an AI tool to follow the book’s AI-generated examples.
Why it matters: You can examine the book’s AI-generated results without signing up for or installing an AI tool.
Key terms: Colaboratory, GitHub Copilot, VSCode IDE, local version of Python, AI tool, source notebooks
2.6 Summary
Where this is used later
- What is a module? (chapter 10) · The use of Colaboratory notebooks as the working environment.
- Installing Python libraries using pip and venv (chapter 19) · Introduces Colaboratory as a Python environment.
- Installing pandas (chapter 24) · Prior familiarity with Jupyter notebooks in Colaboratory.
- Statements, blocks, and indentation (chapter 8) · Earlier experience running code in Colaboratory notebooks.
- (chapter intro) (chapter 11) · Assumes experience writing and running code in Colaboratory.
- Solving the problem with AI code generation (chapter 5) · Provides a reason to scrutinize code produced for the lab with AI code generation.
Concepts explained in this chapter
- Google ColabGoogle Colaboratory is a hosted notebook platform that provides browser-based interactive computing environments, commonly with Python support.
- computational notebookJupyter Notebook is an interactive computational document format and web application that combines executable code, results, and explanatory text.
- cellA notebook cell is a discrete unit in an interactive notebook containing executable code or formatted text.
- code generationCode generation is the automated production of source code from prompts, specifications, templates, or other inputs.
- dir()dir() is Python's built-in function for listing names and attributes available in a namespace or associated with an object, module, or type.
- PythonPython is a high-level general-purpose programming language with an interpreted execution model and dynamic features.
- namespaceA global namespace is the namespace associated with a module, script, or interactive session and visible as the defining environment for its functions.
- conversational aiA chatbot is software that conducts conversational interactions with users through natural-language input and output.
- promptA prompt is an instruction or input supplied to an AI system to elicit a particular response or generated output.
- functionA function is a callable program unit that performs an operation, may accept inputs, and can produce a result or side effect.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
