Upload
mindy-mcadams
View
1.888
Download
2
Embed Size (px)
DESCRIPTION
Brief introduction to the Python programming language, for complete beginners who have never learned a programming language before. Resources and links are included.
Citation preview
L E A R N I N G T O P R O G RA M
PYTHON
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
WHY PYTHON?
Python is one
of the most-
used
programming
languages
today.Source:
https://github.com/mjwillson/ProgLangVisualise
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-J
avaScript-as-a-first-
language
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
I N T E RAC T I V E M O D E
PYTHON
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
T H I S I S A S C R I P T , S H O W N I N A T E XT E D I T O R
PYTHON
When you run a Python script (left) in the Python interpreter, the output (but not the stored script) is displayed onscreen (right).
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
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, whileYou will learn how to do each of these, which is pretty much all there is to programming. (I’m lying a little bit.)
“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
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 doSource: Think Python, by Allen B. Downey (O’Reilly Media: 2012), pages 4–5
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.
• 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
RESOURCES
L E A R N I N G T O P R O G RA M
PYTHON
Presentation by Mindy McAdams, University of Florida[ 2012 ]