# Python Programming/Introduction

This lesson introduces the Python programming language and environment.

## Objectives and Skills

Objectives and skills for this lesson include:
* Introduction
** Need and evolution of Python
** Features of Python
** The Prompt
** Editor and source file
** Translation and executable
* Installation
** Windows and Linux installation

## Readings

* Wikipedia: Python (programming language)
* Wikipedia: Integrated development environment
* Wikipedia: IDLE (Python)
* Python for Everyone: Why should you learn to write programs?

## Multimedia

* YouTube: Python for Informatics: Chapter 1 - Introduction by Chuck Severance
* YouTube: Python Programming by Derek Banas
* YouTube: Installing Python by thenewboston
* YouTube: Installing PyCharm by thenewboston
* YouTube: Python Basics Playlist (21 videos) by John Philip Jones
* YouTube: Learn Python - Full Course for Beginners by freeCodeCamp.org

## Examples
### Comments

A comment starts with a hash character (#) that is not part of a string literal, and ends at the end of the physical line.

### Print

The print function prints objects to standard output or to a text stream.

### Exit

The exit function exits from Python.

## Activities
### Tutorials

* Complete one or more of the following tutorials:
** LearnPython
*** LearnPython: Hello, World!
** TutorialsPoint
*** TutorialsPoint: Python Basic Tutorial
*** TutorialsPoint: Python Overview
*** TutorialsPoint: Environment Setup
** W3Schools
*** W3Schools: Python Tutorial
** Wikiversity
*** Python Concepts/Why learn Python
*** Python Concepts/Introduction and Setup
*** Python Concepts/To Get You Started
** Wikibooks
*** Wikibooks: A Beginner's Python Tutorial/Installing Python
*** Wikibooks: A Beginner's Python Tutorial/Very Simple Programs

### Python

* Learn the differences between Python 2 and Python 3.
** Review Python.org: Should I use Python 2 or Python 3 for my development activity?
* Download and install Python.
** Review TutorialsPoint: Python 3 Environment Setup.
** Download Python from Python.org: Downloads.
** Install Python.
** At a command prompt or terminal window, run the command python -V or python3 -V to confirm Python installation and display the version number.
* Use the Python interpreter.
** At a command prompt or terminal window, run the command python or python3 to start the Python interpreter.
** At the Python prompt, enter print("Hello <name>!"), replacing <name> with your name.
** At the Python prompt, enter exit to exit Python.

### Python IDEs

* Use the Python IDLE integrated development environment.
** Review Wikipedia: IDLE (Python).
** Run IDLE on your system.
** At the Python prompt, enter print("Hello <name>!"), replacing <name> with your name.
** At the Python prompt, enter exit to exit IDLE.
* Download and install another Python integrated development environment (IDE).
** Review TechAltair: 7 Best Python IDE for Pythonist.
** Select and download one of the recommended Python IDEs. Chose PyCharm Community Edition if you are unsure which one to select.
** Install the IDE.
** Run the IDE.
** In a new file, enter print("Hello <name>!"), replacing <name> with your name.
** Save the file as hello.py.
** Run the script and observe the results.
** Exit the IDE.
* Use a free cloud-based Python IDE.
** Review Wikipedia: Cloud9 IDE.
** Create a free account at Cloud9.
** Using Cloud9, create a new private workspace. Name the workspace whatever you like, or use python. Choose Python as the workspace template.
** Once the workspace starts, examine the Cloud9 IDE.
** Cloud9 has both Python 2 and Python 3 installed. At the bash prompt, run the command python to start the Python 2 interpreter.
** At the Python prompt, enter print("Hello <name>!"), replacing <name> with your name.
** At the Python prompt, enter exit to exit Python.
** At the bash prompt, run the command python3 to start the Python 3 interpreter.
** At the Python prompt, enter print("Hello <name>!"), replacing <name> with your name.
** At the Python prompt, enter exit to exit Python.
** Create a new file in the Cloud9 IDE.
** In the new file, enter print("Hello <name>!"), replacing <name> with your name.
** Save the file as hello.py.
** Run the script and observe the results.
** In the lower Run window, change the Runner to Python 3.
** Run the script and observe the results.
** To set Python 3 as the default runner, use Run / Run Configurations / Manage and set Python Version to Python 3.
** Exit Cloud9.

### Games

* Play CodeCombat Kithgard Dungeon levels 1 - 4.

### Documentation

* Read stackoverflow python questions: https://stackoverflow.com/questions/tagged/python?tab=Votes

## Lesson Summary

* Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.
* A high-level programming language is a programming language with strong abstraction from the details of the computer.
* An interpreted language is a programming language for which most of its implementations execute instructions directly, without previously compiling a program into machine-language instructions.
* There are three major versions of Python (1.x, 2.x, and 3.x). Python 2 and Python 3 are both considered current, stable languages. Python 3 is not backward-compatible with Python 2.
* Most Python implementations support a command-line interface / command-line interpreter in which users may enter statements sequentially and receive the results immediately. This sequence is known as a read–eval–print loop (REPL).
* The Python interpreter may also execute scripts, which are collections of Python source code saved as a file or files.
* A variety of Integrated Development Environments (IDEs) are available for Python. IDEs normally consist of a source code editor, build automation tools, and a debugger. Most modern IDEs also have intelligent code completion.
* IDLE (Integrated DeveLopment Environment) is an integrated development environment for Python, which has been bundled with the default implementation of the language since 1.5.2b1.
* A Python comment starts with a hash character (#) that is not part of a string literal, and ends at the end of the physical line.
* The print function prints objects to standard output or to a text stream.
* The exit function exits from Python.
* Python files use the filename extension .py.

## Key Terms
### bug

    An error in a program.

### central processing unit

    The heart of any computer. It is what runs the software that we write; also called “CPU” or “the processor”.

### compile

    To translate a program written in a high-level language into a low-level language all at once, in preparation for later execution.

### high-level language

    A programming language like Python that is designed to be easy for humans to read and write.

### interactive mode

    A way of using the Python interpreter by typing commands and expressions at the prompt.

### interpret

    To execute a program in a high-level language by translating it one line at a time.

### low-level language

    A programming language that is designed to be easy for a computer to execute; also called “machine code” or “assembly language”.

### machine code

    The lowest-level language for software, which is the language that is directly executed by the central processing unit (CPU).

### main memory

    Stores programs and data. Main memory loses its information when the power is turned off.

### parse

    To examine a program and analyze the syntactic structure.

### portability

    A property of a program that can run on more than one kind of computer.

### print statement

    An instruction that causes the Python interpreter to display a value on the screen.

### problem solving

    The process of formulating a problem, finding a solution, and expressing the solution.

### program

    A set of instructions that specifies a computation.

### prompt

    When a program displays a message and pauses for the user to type some input to the program.

### secondary memory

    Stores programs and data and retains its information even when the power is turned off. Generally slower than main memory. Examples of secondary memory include disk drives and flash memory in USB sticks.

### semantics

    The meaning of a program.

### semantic error

    An error in a program that makes it do something other than what the programmer intended.

### source code

    A program in a high-level language.

## Review Questions

* Python is _____. Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.
* A high-level programming language is _____. A high-level programming language is a programming language with strong abstraction from the details of the computer.
* An interpreted language is _____. An interpreted language is a programming language for which most of its implementations execute instructions directly, without previously compiling a program into machine-language instructions.
* There are _____ major versions of Python. They are _____. There are three major versions of Python. They are 1.x, 2.x, and 3.x.
* Python 2 and Python 3 are both considered _____. Python 2 and Python 3 are both considered current, stable languages.
* Python 3 is _____-compatible with Python 2. Python 3 is not backward-compatible with Python 2.
* Most Python implementations support a command-line interface / command-line interpreter in which ____. This sequence is known as a ____. Most Python implementations support a command-line interface / command-line interpreter in which users may enter statements sequentially and receive the results immediately. This sequence is known as a read–eval–print loop (REPL).
* The Python interpreter may also execute _____. The Python interpreter may also execute scripts, which are collections of Python source code saved as a file or files.
* A variety of _____ (IDEs) are available for Python. IDEs normally consist of _____, _____ and _____. Most modern IDEs also have _____. A variety of Integrated Development Environments (IDEs) are available for Python. IDEs normally consist of a source code editor, build automation tools and a debugger. Most modern IDEs also have intelligent code completion.
* IDLE (Integrated DeveLopment Environment) is _____. IDLE (Integrated DeveLopment Environment) is an integrated development environment for Python, which has been bundled with the default implementation of the language since 1.5.2b1.
* A Python comment starts with _____, and ends _____. A Python comment starts with a hash character (#) that is not part of a string literal, and ends at the end of the physical line.
* The print function _____. The print function prints objects to standard output or to a text stream.
* The exit function _____. The exit function exits from Python.
* Python files use the filename extension _____. Python files use the filename extension .py.
* The difference between a high-level and low-level programming language is _____. A high-level programming language is easy for humans to understand, while a low-level programming language is harder to understand by a programmer but runs faster.

## Assessments

* Flashcards: Quizlet: Python - Introduction
* Quiz: Quizlet: Python - Introduction

## See Also

* Python.org: Using the Python Interpreter
* Python basics - tutorial with exercises
* SoloLearn: Python
* Open Book Project: Python 3 - The way of the program
* PEP8 Online: Python Formatting