Outline for April 3, 2014
Reading
: § 2
Python, files and shells
Python: programming
language
that you use to tell the computer what to do
Shell: what you can type Python statements directly into, to see what they do
IDLE: the program that
interprets
Python statements (executes the Python program)
File: type Python statements into this, and then have IDLE execute those statements by running the program in the file
First program: hello, world [
hello0.py
]
Explain printing
Demonstrate program in IDLE
Variables
What they are
Variable names
Variable types (int, float, string)
Python keywords
Statements
Simple assignment:
variable = expression
Expressions
Operators
+
,
-
,
*
,
/
,
//
,
%
,
**
Precedence
Parentheses for grouping (
(
,
)
)
Exponentiation (
**
); associates right to left
Positive, negative (unary
+
,
-
)
Multiplication, division, integer division, remainder (
*
,
/
,
//
,
%
)
Addition, subtraction (binary
+
,
-
)
In general, operators of equal precedence are evaluated from the left to the right (associativity); exception noted above
Examples
Temperature conversion [
temp.py
]
Compute the hypotenuse of a right triangle [
hypotnoex.py
]
The difference between strings and integers [
twoplustwo.py
]
Difference between
’2 + 2’
,
2 + 2
Print statements usually end lines
Getting print statements not to end lines
You can also obtain a PDF version of this.
Version of April 4, 2014 at 9:10PM