Hands-onPythonTutorial.pdf
(
775 KB
)
Pobierz
Hands-on Python Tutorial
Release 1.0 for Python Version 3.1+
Dr. Andrew N. Harrington, Loyola University Chicago
March 06, 2015
CONTENTS
1
Beginning With Python
1.1 Context
. . . . . . . . . . . . . . . . . . . . . .
1.2 The Python Interpreter and Idle, Part I
. . . . . .
1.3 Whirlwind Introduction To Types and Functions
1.4 Integer Arithmetic
. . . . . . . . . . . . . . . .
1.5 Strings, Part I
. . . . . . . . . . . . . . . . . . .
1.6 Variables and Assignment
. . . . . . . . . . . .
1.7 Print Function, Part I
. . . . . . . . . . . . . . .
1.8 Strings Part II
. . . . . . . . . . . . . . . . . . .
1.9 The Idle Editor and Execution
. . . . . . . . . .
1.10 Input and Output
. . . . . . . . . . . . . . . . .
1.11 Defining Functions of your Own
. . . . . . . . .
1.12 Dictionaries
. . . . . . . . . . . . . . . . . . . .
1.13 Loops and Sequences
. . . . . . . . . . . . . .
1.14 Decimals, Floats, and Floating Point Arithmetic
1.15 Summary
. . . . . . . . . . . . . . . . . . . . .
Objects and Methods
2.1 Strings, Part III
. . . . . . .
2.2 More Classes and Methods
.
2.3 Mad Libs Revisited
. . . . .
2.4 Graphics
. . . . . . . . . .
2.5 Files
. . . . . . . . . . . .
2.6 Summary
. . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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On Flow of Control
3.1 If Statements
. . . . . . . . . . . .
3.2 Loops and Tuples
. . . . . . . . . .
3.3 While Statements
. . . . . . . . . .
3.4 Arbitrary Types Treated As Boolean
3.5 Further Topics to Consider
. . . . .
3.6 Summary
. . . . . . . . . . . . . .
Dynamic Web Pages
4.1 Overview
. . . . . . . . . . . . .
4.2 Web page Basics
. . . . . . . . .
4.3 Composing Web Pages in Python
4.4 CGI - Dynamic Web Pages
. . . .
4.5 Summary
. . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Index
i
ii
CHAPTER
ONE
BEGINNING WITH PYTHON
© Released under the Creative commons Attribution-Noncommercial-Share Alike 3.0 United States License
http://creativecommons.org/licenses/by-nc-sa/3.0/us/
1.1 Context
You have probably used computers to do all sorts of useful and interesting things. In each application, the computer
responds in different ways to your input, from the keyboard, mouse or a file. Still the underlying operations are
determined by the design of the program you are given. In this set of tutorials you will learn to write your own
computer programs, so you can give the computer instructions to react in the way
you
want.
1.1.1 Low-Level and High-Level Computer Operations
First let us place Python programming in the context of the computer hardware. At the most fundamental level in the
computer there are instructions built into the hardware. These are very simple instructions, peculiar to the hardware
of your particular type of computer. The instructions are designed to be simple for the hardware to execute, not for
humans to follow. The earliest programming was done with such instructions. If was difficult and error-prone. A
major advance was the development of higher-level languages and translators for them. Higher-level languages allow
computer programmers to write instructions in a format that is easier for humans to understand. For example
z = x+y
is an instruction in many high-level languages that means something like:
1. Access the value stored at a location labeled x
2. Calculate the sum of this value and the value stored at a location labeled y
3. Store the result in a location labeled z.
No computer understands the high-level instruction directly; it is not in
machine language.
A special program must
first translate instructions like this one into machine language. This one high-level instruction might be translated into
a sequence of three machine language instructions corresponding to the three step description above:
0000010010000001
0000000010000010
0000010110000011
Obviously high-level languages were a great advance in clarity!
If you follow a broad introduction to computing, you will learn more about the layers that connect low-level digital
computer circuits to high-level languages.
1
Plik z chomika:
Expearre4
Inne pliki z tego folderu:
Expert Python Programming (2008).pdf
(10481 KB)
think_python.pdf
(12457 KB)
Python Data Visualization Cookbook - Milovanovic, Igor-signed.pdf
(14987 KB)
Python Cookbook, 3rd Edition.pdf
(10240 KB)
Black Hat Python.pdf
(7056 KB)
Inne foldery tego chomika:
Algo
C++
HTML
JavaScript
Lua
Zgłoś jeśli
naruszono regulamin