Elements of Python Programming.

adventurescoldΛογισμικό & κατασκευή λογ/κού

7 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

148 εμφανίσεις

Elements of Python Programming.
Mechanical Engineering Report 2005/16
P.A.Jacobs
School of Engineering
The University of Queensland.
September 2005
Abstract
This report introduces Python as a procedural programming language so that can be used
to implement engineering analysis programs or to write problem-description files for large sim-
ulation programs that happen to use Python as a scripting language.These notes were scanned
from material presented in the first few lectures of the course MECH2700,Engineering Analysis
I.They describe just enough of the Python programming language to implement the numerical
methods that are introduced and used in the later parts of the course.
Contents
1 Introduction:Where to begin...2
2 The Python interpreter 4
3 An example program 5
3.1 Staged development of the code..............................8
4 Model of a computer 10
5 Python language elements 15
5.1 Lexical structure......................................16
5.2 Lines and indentation....................................17
5.3 Tokens............................................19
5.4 Statements..........................................23
5.5 Data types..........................................24
5.6 Variables,assignments,name spaces............................29
5.7 Expressions and operators.................................30
6 The print statement 33
7 Flow-Control statements 34
8 Functions 39
9 Modules 43
10 Scope and name resolution 45
1
1 Introduction:Where to begin...
2
3
2 The Python interpreter
4
3 An example program
5
6
7
3.1 Staged development of the code
8
9
4 Model of a computer
10
11
12
13
14
5 Python language elements
Much of the material on the following pages is from
Alex Martelli
Python in a Nutshell
O’Reilly,First Edition March 2003
ISBN:0-596-00188-6
15
5.1 Lexical structure
16
5.2 Lines and indentation
17
18
5.3 Tokens
19
20
21
22
5.4 Statements
23
5.5 Data types
24
25
26
27
28
5.6 Variables,assignments,name spaces
29
5.7 Expressions and operators
30
31
32
6 The print statement
33
7 Flow-Control statements
34
35
36
37
38
8 Functions
39
40
41
42
9 Modules
43
44
10 Scope and name resolution
45
46