View on GitHub

GettingStartedWithPythonDemo

Python Basics

In this demo we will cover the basics of installing, running, and programming with Python. By the end of this demonstration you will know how Python can be installed and used on your Mac or Windows computer.

Python Website

Figure 1. Python.org Website

What is Python?

Python is a simple yet powerful programing language. It is an easy language to learn but still powerful due to the extensive pre-made code modules you can download freely (code modules are files with code in them.)

Here are some good facts to know about Python:

Installing Python

Python is easy to download and install. A quick internet search will provide you with a download link and several installation videos based on your chosen OS. https://www.google.com/search?q=How+to+install+python (external site).

You must first download the installation program from the https://www.python.org/downloads/ website (Figure 2). This page is context-sensitive, so it should recognize your OS and then provide the appropriate download option. Afterward, you run the Windows .exe or the macOS .pkg file to begin installing.

Steps:

  1. Navigate to Python.Org (external Site)
  2. Select Download Python.
  3. Run the exe or pkg file.

The Python Download page

Figure 2. Downloading Python’s installation program

For a Windows installation, I recommend you check the checkbox to include Python’s executable in the OS path, then click the custom option to choose an easy-to-access location like C.\Python\Python3.x for its installation folder (Figure 3).

Steps:

  1. Check Add Python to Path checkbox.
  2. Select Customize Installation.
  3. Select Next to advance dialog.
  4. Configure Customize install location textboxt.
  5. Select Install

The Python Installation app on Windows

Figure 3. Customizing the Python installation

The Mac installer has fewer options than the Windows version and more text to read, but selecting the default options is fine. Your newly installed files will appear in Finder (Figure 4).

Steps:

  1. Read the introduction page, then select Continue
  2. Read the Read Me page, then select Continue
  3. Read the License page, then select Continue
  4. Select Agree to continue the installation
  5. Read the Installation Type page, then select Install
  6. Close Finder after it appears

The Python Installation app on Mac

Figure 4. The Python installation on Mac OS

Important: Restarting your Mac is recommended after the installation and may be required on some computers.

Demonstration

In this demonstration, we will walk through the process of installing Python on a Windows computer. You are encouraged to follow along if you would like. Though this demo will be on Windows, you can follow on a Mac, but remember that you may have to restart your computer and log back into the session.

This demo consists of the following steps:

  1. Download the Python installer from Python.Org.
  2. Run the installation program.

In this demonstration, you saw how to install Python on a Windows computer. Next, we will look at how to use your installation.


Running Python

Once you have installed Python, you can run Python code interactively using a Console/Terminal or create a script with its code editor IDLE. Both options have their place, and I recommend you use both.

The Console/Terminal Interface

To open a command console in Windows 10, click the Start button, then type in the command __CMD__ into Open the textbox. Clicking the Command Prompt App option opens a command prompt window. With the Command Prompt open, type Python.exe to begin an interactive session (Figure 5).

Steps:

  1. Select Start
  2. Type CMD
  3. Select Command Prompt App

Starting Python's interactive mode on Windows

Figure 5. The Run dialog window

It is almost the same if you use a Mac, but now the Command Prompt is called a “Terminal” window. Open a Terminal window using Finder > Applications > Utilities > Terminal.app. You can access Python’s interactive mode by typing in the “Python3” command in the Terminal window (Figure 6).

Steps:

  1. Open Finder
  2. Navigate to Utilities
  3. Open Terminal.app

Starting Python's interactive mode on Mac OS

Figure 6. A Mac Command prompt

Note: The macOS includes Python 2.x, so use the correct version when running your code. On Mac, typing python3 will connect to your Python 3.x installation, while typing python connects to the Python 2.x installation. You can verify the version you are running using the -V switch from the command terminal of your computer (Figure 7).

Testing Pythons version with -V

Figure 7. Running multiple versions of Python on the Mac OS

Demonstration

In this demonstration, we will walk through the process of using Python’s Interactive console/terminal application. You are encouraged to follow along if you would like. Though I will be using Windows, the process is very similar on macOS.

This demo consists of the following steps:

  1. Open a command prompt and start Python in interactive mode.
  2. Use the following common commands, one at a time, to show how the interactive mode works.
 first_name = input("Enter your first name")
 last_name = input("Enter your last name")
 print("You entered:", first_name, last_name)

Note: You can copy the Python code here demo01.py

In this demonstration, we learned how to use Python’s Interactive console/terminal application. Next, we will learn about Python’s built-in code editor.


The IDLE Code Editor

You can create and run Python code files (Scripts) using its built-in code editor called IDLE (figure 8). Code editors are like text editors, but they also allow you to run your code.

Python's Editor IDLE

Figure 8. The Python’s IDLE Application

IDLE has limited features, but it is good enough when first learning Python. You can find out more about its features via an internet search; https://www.google.com/search?q=How+to+use+Python+idle (external site).

To start using IDLE you must first start it. The steps are only slightly different between Mac and Windows (figure 9).

Steps for Windows:

  1. Click the Start menu icon.
  2. Type idle to search for the application.
  3. Launch IDLE from the menu presented.

Steps for macOS:

  1. Click on Finder.
  2. Type in idle.app to search for the application.
  3. Launch IDLE.app when the is file found.

Starting Python's Windowed Editor IDLE

Figure 9. Steps to open the Python’s IDLE Application

Once IDLE opens, you can use its interactive mode as you do from a console/terminal window or create script files using the File > New File menu item.

Demonstration

In this demonstration, we will walk through the process of using Python’s IDLE code editor. You are encouraged to follow along if you would like. Though I will be using Windows, the process is very similar on macOS.

This demo consists of the following steps:

Interactive Mode

  1. Open IDLE.
  2. Note that IDLE starts in interactive mode.
  3. Use the following common commands, one at a time, to show how the interactive mode works.
 first_name = input("Enter your first name")
 last_name = input("Enter your last name")
 print("You entered:", first_name, last_name)

Note: You can copy the Python code here demo01.py

Creating Scripts

  1. Select File > New File.
  2. Type, or copy and paste, code into the text area.
  3. Select Run > Run Module.
  4. Select OK to save the file.
  5. Save file as _test.py.
  6. Note that the results are displayed in the interactive window.

In this demonstration, you saw how to use Python’s code editor IDLE. Many editors are available for working with Python, but this is the one that comes with a Python installation.


The Python interpreter

Whether you use the interactive console/terminal or the windowed editor option, the code you enter is sent to the Python interpreter for processing (figure 10). This interpreter application is what we refer to when we say your code runs on Python.

Pythons apps work with the Python Interpreter

Figure 10. The Python interpreter

Summary

In this session, learned how to install and start programming in Python. While we only covered the basics, I have more share if you are interested. My contact info is on the Google Slides presentation.