Python Programming/Introduction

This lesson introduces the Python programming language and environment.

Objectives and Skills

edit

Objectives and skills for this lesson include:[1]

  • Introduction
    • Need and evolution of Python
    • Features of Python
    • The Prompt
    • Editor and source file
    • Translation and executable
  • Installation
    • Windows and Linux installation

Readings

edit
  1. Wikipedia: Python (programming language)
  2. Wikipedia: Integrated development environment
  3. Wikipedia: IDLE (Python)
  4. Python for Everyone: Why should you learn to write programs?

Multimedia

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

Examples

edit

Comments

edit

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

# This is a comment

Print

edit

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

# This script demonstrates a Python print statement.

print("Hello Wikiversity!")

Exit

edit

The exit function exits from Python.[4]

exit()

Activities

edit

Tutorials

edit
  1. Complete one or more of the following tutorials:

Python

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

Python IDEs

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

Games

edit
  1. Play CodeCombat Kithgard Dungeon levels 1 - 4.

Documentation

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

Lesson Summary

edit
  • Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.[5]
  • A high-level programming language is a programming language with strong abstraction from the details of the computer.[6]
  • 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.[7]
  • 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.[8]
  • 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).[9]
  • The Python interpreter may also execute scripts, which are collections of Python source code saved as a file or files.[10]
  • 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.[11]
  • 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.[12]
  • 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.[13]
  • The print() function prints objects to standard output or to a text stream.[14]
  • The exit() function exits from Python.[15]
  • Python files use the filename extension .py.[16]

Key Terms

edit
bug
An error in a program.[17]
central processing unit
The heart of any computer. It is what runs the software that we write; also called “CPU” or “the processor”.[18]
compile
To translate a program written in a high-level language into a low-level language all at once, in preparation for later execution.[19]
high-level language
A programming language like Python that is designed to be easy for humans to read and write.[20]
interactive mode
A way of using the Python interpreter by typing commands and expressions at the prompt.[21]
interpret
To execute a program in a high-level language by translating it one line at a time.[22]
low-level language
A programming language that is designed to be easy for a computer to execute; also called “machine code” or “assembly language”.[23]
machine code
The lowest-level language for software, which is the language that is directly executed by the central processing unit (CPU).[24]
main memory
Stores programs and data. Main memory loses its information when the power is turned off.[25]
parse
To examine a program and analyze the syntactic structure.[26]
portability
A property of a program that can run on more than one kind of computer.[27]
print statement
An instruction that causes the Python interpreter to display a value on the screen.[28]
problem solving
The process of formulating a problem, finding a solution, and expressing the solution.[29]
program
A set of instructions that specifies a computation.[30]
prompt
When a program displays a message and pauses for the user to type some input to the program.[31]
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.[32]
semantics
The meaning of a program.[33]
semantic error
An error in a program that makes it do something other than what the programmer intended.[34]
source code
A program in a high-level language.[35]

Review Questions

edit
Enable JavaScript to hide answers.
Click on a question to see the answer.
  1. Python is _____.
    Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.
  2. A high-level programming language is _____.
    A high-level programming language is a programming language with strong abstraction from the details of the computer.
  3. 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.
  4. There are _____ major versions of Python. They are _____.
    There are three major versions of Python. They are 1.x, 2.x, and 3.x.
  5. Python 2 and Python 3 are both considered _____.
    Python 2 and Python 3 are both considered current, stable languages.
  6. Python 3 is _____-compatible with Python 2.
    Python 3 is not backward-compatible with Python 2.
  7. 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).
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. The print() function _____.
    The print() function prints objects to standard output or to a text stream.
  13. The exit() function _____.
    The exit() function exits from Python.
  14. Python files use the filename extension _____.
    Python files use the filename extension .py.
  15. 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

edit

See Also

edit

References

edit
  1. Vskills: Certified Python Developer
  2. Python.org: Lexical analysis
  3. Python.org: Built-in Functions
  4. Python.org: System-specific parameters and functions
  5. Wikipedia:Python (programming language)
  6. Wikipedia: High-level programming language
  7. Wikipedia: Interpreted language
  8. Wikipedia:Python (programming language)
  9. Wikipedia:Python (programming language)
  10. Wikipedia: Scripting language
  11. Wikipedia: Integrated development environment
  12. Wikipedia: IDLE (Python)
  13. Python.org: Lexical analysis
  14. Python.org: Built-in Functions
  15. Python.org: System-specific parameters and functions
  16. Wikipedia:Python (programming language)
  17. PythonLearn: Why should you learn to write programs?
  18. PythonLearn: Why should you learn to write programs?
  19. PythonLearn: Why should you learn to write programs?
  20. PythonLearn: Why should you learn to write programs?
  21. PythonLearn: Why should you learn to write programs?
  22. PythonLearn: Why should you learn to write programs?
  23. PythonLearn: Why should you learn to write programs?
  24. PythonLearn: Why should you learn to write programs?
  25. PythonLearn: Why should you learn to write programs?
  26. PythonLearn: Why should you learn to write programs?
  27. PythonLearn: Why should you learn to write programs?
  28. PythonLearn: Why should you learn to write programs?
  29. PythonLearn: Why should you learn to write programs?
  30. PythonLearn: Why should you learn to write programs?
  31. PythonLearn: Why should you learn to write programs?
  32. PythonLearn: Why should you learn to write programs?
  33. PythonLearn: Why should you learn to write programs?
  34. PythonLearn: Why should you learn to write programs?
  35. PythonLearn: Why should you learn to write programs?