Head First Python
by Paul Barry
Copyright 2023 Paul Barry. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com.
- Acquisitions Editor: Suzanne McQuade
- Development Editor: Melissa Potter
- Production Editor: Beth Kelly
- Copyeditor: FILL IN COPYEDITOR
- Proofreader: FILL IN PROOFREADER
- Indexer: FILL IN INDEXER
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Kate Dullea
- August 2023: Third Edition
Revision History for the Early Release
- 2023-02-08: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781492051299 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Head First Python, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the author and do not represent the publishers views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-492-05122-0
[FILL IN]
Preface
Install the latest Python 3
What you do here depends on the platform youre running, which is assumed to be one of Windows, macOS, or Linux.
The good news is that all three platforms run that latest Python, release 3.10. Theres no bad news.
If you are already running release 3.10 or later, move to the next page youre ready. If you havent already installed Python or are using an older version, select the paragraph below which applies to you, and read on.
Installing on Windows
The wonderful Python folk at Microsoft work hard to ensure the most-recent release of Python is always available to you via the Windows Store application. Open the Store, search for Python, select the most-recent version, then click the Get button. Watch patiently while the progress indicator moves from zero to 100% then, once the install completes, move to the next page youre ready.
Installing on macOS
The latest Macs ship with older, out-of-date releases of Python. Dont use these. Instead, head over to Pythons home on the web, https://www.python.org/, then click on the Downloads option. The latest release of Python 3 should being to download, as the Python site is smart enough to spot youre connecting from a Mac. Once the download completes, run the installer thats waiting for you in your Downloads folder. Click the Next button until there are no more Next buttons to click then, when the install is complete, move to the next page youre ready.
Note
Theres no need to remove the older pre-installed releases of Python which come with your Mac. This install will supersede them.
Installing on Linux
The Head First Coders are a rag-tag team of techies whose job is to keep the Head First Authors on the straight and narrow (no mean feat). The coders love Linux and the Ubuntu distribution, so thats discussed here.
It should come as no surprise that the latest Ubuntu comes with Python 3 installed and up-to-date. If this is the case, cool, youre all set. If you are using a Linux distribution other than Ubuntu, use your systems package manager to install Python 10 (or later) into your Linux system. Once done, move to the next page youre ready.
Lets complete your install with two things: a required back-end dependency, as well as a modern, Python-aware text editor.
Python on its own is not enough
In order to explore, experiment, and learn about Python, you need to install a runtime back-end called Jupyter into your Python. As youll see in a moment, doing so is straightforward.
When it comes to creating Python code, you can use just about any programmers editor, but were recommending you use a specific one when working through this books material: Microsofts Visual Studio Code, known the world over as VS Code.
Install the latest Jupyter Notebook back-end
Note
Dont worry, youll learn all about what this is used for soon!
Regardless of the operating system youre running, make sure youre connected to the Internet, open a Terminal window, then type:
python3 -m pip install jupyterA veritable slew of status messages whiz by on screen. If you are seeing a message near the end stating everything is Successfully installed, then youre golden. If not, check the Jupyter docs and try again.
Install the latest release of VS Code
Grab your favorite browser and surf on over to the VS Code download page:
https://code.visualstudio.com/Download
Note
Their are alternatives to VS Code, but in our view VS Code is hard to beat when it comes to this books material. And, no, we are *not* part of some global conspiracy to promote Microsoft products!!
Pick the download which matches your environment, then wait for the download to complete. Follow the instructions from the site to install VS Code, then flip the page to learn how to complete your VS Code setup.
Configure VS Code to your taste
Go ahead and run VS Code for the first time. From the menu, select the File, then Preferences, then Settings to access the editors settings preferences.
You should see something like this:
Note
On the Mac, start with the Code menu.
Until you become familiar with VS Code, you may wish to configure your editor to match the settings preferred by the