Brief introduction to the Python programming language, for complete beginners who have never learned a programming language before. Resources and links are included.
2. WHY LEARN TO PROGRAM?
• An important skill in making things for online media:
problem solving
• Process of learning to program: Practice and
improve your problem-solving skills
• Thinking in a structured way
• Learning how to find answers by a combination of
online searching and trial-and-error
3. WHY PYTHON?
Python is one of
the most-used
programming
languages
today.
Source: https://github.com/mjwillson/ProgLangVisualise
4. WHY NOT JAVASCRIPT?
• JavaScript is a must for Web development today.
• If you already knew how to program, you could jump
straight into JavaScript and not learn Python.
• As a first programming language, Python is easier to
learn than JavaScript.
• The techniques you learn as you learn Python will help
you understand JavaScript more quickly.
http://www.quora.com/Is-it-better-to-learn-Python-or-
JavaScript-as-a-first-language
5. USING PYTHON
• There are two ways to use Python:
• Interactive mode
• Script mode
• In interactive mode, you type Python programs and
the Python interpreter displays the result
immediately …
Source: Think Python, by Allen B. Downey (O’Reilly Media: 2012), pages 2–3
7. USING PYTHON
• There are two ways to use Python:
• Interactive mode
• Script mode
• In script mode, you write code in a text file, save it,
and then use the interpreter to execute (or run) the
contents of the file (which is called a script)
• Python scripts have filenames that end with .py
Source: Think Python, by Allen B. Downey (O’Reilly Media: 2012), pages 2–3
9. When you run a Python script (left) in the Python
interpreter, the output (but not the stored script) is
displayed onscreen (right).
10. WHAT A PROGRAM DOES
• Input: Get data from the keyboard, a file, or some other
device
• Output: Display data on the screen, or send data to a file or
other device
• Math: Perform basic mathematical operations like addition
and multiplication
• Conditional execution: Check for certain conditions and
execute the appropriate code
• Repetition: Perform some action repeatedly, usually with some
variation
Source: Think Python, by Allen B. Downey (O’Reilly Media: 2012), page 3
11. WHAT A PROGRAM DOES (2)
• Input: (1) run a script; (2) raw_input
• Output: (1) print; (2) create and write to text files
• Math: +, –, /, *, %, >, <, >=, <=, ==
• Conditional execution: if, elif, else
• Repetition: for, while
You will learn how to do each of these, which is pretty much
all there is to programming. (I’m lying a little bit.)
12. ―Every program you’ve ever used, no
matter how complicated, is made up of
instructions that look pretty much like
these. So you can think of programming as
the process of breaking a large, complex
task into smaller and smaller subtasks until
the subtasks are simple enough to be
performed with one of these basic
instructions.‖
Source: Think Python, by Allen B. Downey (O’Reilly Media: 2012), page 4
13. DEBUGGING
Errors are bugs. Finding and fixing them is debugging.
• Syntax errors: Structure and rules, such as:
―Parentheses come in pairs‖
• Runtime errors: Appear while the program is running
(these are called exceptions)
• Semantic errors: Your script runs but does not do
what you wanted it to do
Source: Think Python, by Allen B. Downey (O’Reilly Media: 2012), pages 4–5
14. In the practice of programming—of writing
programs—a lot of the work is in the
debugging.
Each error becomes a puzzle to be solved.
―Why doesn’t it work the way I want it to
work?‖
The process of learning to program is a
process of problem-solving.
15. RESOURCES
• Think Python, by Allen B. Downey
http://www.greenteapress.com/thinkpython/
• Learn Python the Hard Way, by Zed A. Shaw
http://learnpythonthehardway.org/
• Codecademy: Python
http://www.codecademy.com/tracks/python
16. PYTHON
LEARNING TO PROGRAM
Presentation by Mindy McAdams, University of Florida
[ 2012 ]