Introduction to Programming

What is a Program?

A computer program is a sequence of instructions to be executed by a computer to perform one or more tasks. The term code is often used to refer to some or all of the instructions within a computer program. Programming refers to the act of writing a computer program.

A programming language is a collection of keywords and syntactical rules that can be used to write the instructions contained within a computer program. There are many different programming languages available today. Some of the most popular languages today are C++, Java, Python, R, Javascript, Scala, and PHP. Some languages are designed to focus on or excel at specific types of tasks, while others are considered to be “general-purpose” languages that can be used for almost any programming task. The languages are created with different design philosophies in mind, and they each have their own strengths and weaknesses.

While there are many important differences between programming languages, most languages also have a lot of similarities. Once you learn how to program in one language, you will have a good understand of how a programming language is structured, and you should find it much easier to learn additional languages in the future.

What is Python?

Python is a general-purpose programming language designed by Guido van Rossum and first released to the public in 1991. Python was designed to be relatively easy to learn, and to be easily readable. It is freely available, and has an active community of developers who freely distribute third-party libraries that can be used to extend the functionality of Python. It is not the fastest programming language. Programs written in Java or C++ will likely run much more quickly than a similar program written in Python. Never-the-less, Python is currently the fastest-growing programming language because of its ease-of-use and active community of developers, among other reasons.

Programming Environments

A programming environment is a set of tools that are used to write and execute computer programs. Every Python environment will include a Python interpreter, which is a program that executes commands that are written in the Python language. Lines of Python code can be provided directly to an interpreter one-at-a-time through a console or terminal application, but it usually more convenient to create a file that contains several lines of code and then provide the file to the interpreter for execution. It is possible to write Python code in a simple text editor such as Notepad, but it is more common to use an integrated development environment, or IDE. And IDE is a set of tools used to write, manage, and debug code. An IDE will contain an editor used to write code, but will also contain additional features designed specifically to assist with writing code. Most IDEs will also connect directly to the interpreter so that you can submit your code to be ran directly from the IDE itself. When working in an IDE, it is easy to forget that the interpreter exists, but it is important to remember that there is another program in the background that is actually executing your code.

Scripts and Notebooks

A Python script is a simple plain-text file that contains lines of Python code. Some of the most popular IDEs for writing Python scripts are PyCharm, Spyder, Atom, and Thonny. Traditionally, most Python programs have been written as scripts.

A modern alternative to a script-based IDE is Jupyter Notebook. Instead of plain-text scripts, Jupyter uses a notebook format that allows for code to be presented alongside formatted text. A notebook consists of multiple cells of various types. Markdown cells contain formatted text, images, embedded videos, links, and other types of content. Code cells contain lines of Python code that can be executed within the notebook. If a particular code cell generates output, then that output will be displayed directly beneath the cell. Notebooks are useful for creating presentations and reports that contain executable code along with formatted text and other media. The Jupyter Notebook environment has become particularly prominent within the Data Science community.

The Anaconda Distribution

The Anaconda Distribution is a collection of bundled software designed to help you quickly set up with a Python environment. The distribution includes Python, Spyder, and Jupyter, as well as several other tools that we have not yet discussed. We will be using the Anaconda distribution in this class, since it is perhaps the easiest way to quickly get up and running.

Instructions for installing Anaconda are provided below.

Please following the instructions below to install the Anaconda distribution.

  1. Download Anaconda. Select the Python 3.7 version of the installer. Be sure to select the correct operating system.

  2. Run the installer. This will install Python, as well as the Jupyter Notebook and Spyder IDEs.

  3. You can accept most of the default settings, with one exception. If you are working in Windows, then when you get to the screen shown below, I recommend checking the first box, labeled “Add Anaconda to my PATH environment variable.” You will see a message saying that this is not recommended, but it will not harm your computer in any way, and will provide you with additional options for launching Jupyter. This step is required if you would like to work with notebooks stored on a USB drive.

  4. If you already have a previous version of Anaconda installed on your computer, you can update to the most recent version by opening a command prompt and typing the command shown below. If you have issues running certain applications or packages after updating Anaconda, you might trying uninstalling Anaconda and then reinstalling it.

    conda update –all