Python Programming/Introduction
Appearance
This lesson introduces the Python programming language and environment.
Objectives and Skills
[edit | edit source]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 | edit source]- Wikipedia: Python (programming language)
- Wikipedia: Integrated development environment
- Wikipedia: IDLE (Python)
- Python for Everyone: Why should you learn to write programs?
Multimedia
[edit | edit source]- 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
[edit | edit source]Comments
[edit | edit source]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
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 | edit source]The exit function exits from Python.[4]
exit()
Activities
[edit | edit source]Tutorials
[edit | edit source]- Complete one or more of the following tutorials:
- LearnPython
- TutorialsPoint
- W3Schools
- Wikiversity
- Wikibooks
Python
[edit | edit source]- Learn the differences between Python 2 and Python 3.
- 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
orpython3 -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
orpython3
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.
- At a command prompt or terminal window, run the command
Python IDEs
[edit | edit source]- 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
[edit | edit source]- Play CodeCombat Kithgard Dungeon levels 1 - 4.
Documentation
[edit | edit source]- Read stackoverflow python questions: https://stackoverflow.com/questions/tagged/python?tab=Votes
Lesson Summary
[edit | edit source]- 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 | edit source]- 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 | edit source]-
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
[edit | edit source]- Flashcards: Quizlet: Python - Introduction
- Quiz: Quizlet: Python - Introduction
See Also
[edit | edit source]- 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
References
[edit | edit source]- ↑ Vskills: Certified Python Developer
- ↑ Python.org: Lexical analysis
- ↑ Python.org: Built-in Functions
- ↑ Python.org: System-specific parameters and functions
- ↑ Wikipedia:Python (programming language)
- ↑ Wikipedia: High-level programming language
- ↑ Wikipedia: Interpreted language
- ↑ Wikipedia:Python (programming language)
- ↑ Wikipedia:Python (programming language)
- ↑ Wikipedia: Scripting language
- ↑ Wikipedia: Integrated development environment
- ↑ Wikipedia: IDLE (Python)
- ↑ Python.org: Lexical analysis
- ↑ Python.org: Built-in Functions
- ↑ Python.org: System-specific parameters and functions
- ↑ Wikipedia:Python (programming language)
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?
- ↑ PythonLearn: Why should you learn to write programs?