


see program:
http://www.annedawson.net/PythonPrograms.txt
04-01.py



see program:
http://www.annedawson.net/PythonPrograms.txt
04-02.py

A representation of the memory location of an object
can be obtained by using the id function.
number1 = raw_input("Enter first
number:\n")
print number1, type(number1), id(number1)
number1 = int(number1)
print number1, type(number1) ), id(number1)
see program:
http://www.annedawson.net/PythonPrograms.txt
04-03.py
see program:
http://www.annedawson.net/PythonPrograms.txt
04-04.py
see program:
http://www.annedawson.net/PythonPrograms.txt
04-05.py
see program:
http://www.annedawson.net/PythonPrograms.txt
04-06.py
These are Boolean expressions.
The result of these expressions is either true (1) or
false (0).
see program:
http://www.annedawson.net/PythonPrograms.txt
04-07.py
see program:
http://www.annedawson.net/PythonPrograms.txt
04-08.py
see program:
http://www.annedawson.net/PythonPrograms.txt
04-09.py



(lowest
precedence)
(highest
precedence)
The if statement starts with the keyword if followed
by a Boolean expression, followed by a colon (:).
Beneath the if line, the
statements to be run if the condition is true are entered after pressing the
Tab key or typing a few space characters.
The if statement makes use of a Boolean
expression to decide which statement(s) to execute.
The Boolean expression in this
example is:
x ==
'spam'
The expression has a value of true or false (1 or 0).
The Boolean expression is also known
as the condition of the if statement.
If the condition is true,
the first print statement is executed and the second
one is skipped.
If the condition is false,
the first print statement is skipped and the second
one is executed.
It's possible to have multiple
statements in the true or false sections
of an if
statement...
If the condition is true, the
first two print statements are executed
and the second set are skipped.
The if statement starts with the keyword if followed
by a Boolean expression, followed by a colon (:).
Beneath the if line, the
statements to be run if the condition is true are entered after pressing the Tab
key or typing a few space characters.
The statements to be run must
be indented to the same level.
It's recommended to press the Tab
key before typing the statements.

The else part of an if statement
is optional, but if included, must be followed by a colon (:), and
then the indented statement(s) to be executed if the condition is false.
see programs:
http://www.annedawson.net/PythonPrograms.txt
04-10.py
04-11.py
04-12.py
Nested if/else statements test for multiple cases
by placing if/else selection structures inside other
if/else selection structures

see programs:
http://www.annedawson.net/PythonPrograms.txt
04-13.py
04-14.py
Nested if/else statements can be written using an alternate if/elif/else construct.
Program 04-14.py is exactly equivalent to 04-15.py.

see program:
http://www.annedawson.net/PythonPrograms.txt
04-15.py
1. A not and is equivalent to an or with two negated inputs.
2. A not or is equivalent to an and with two negated inputs.
see program:
http://www.annedawson.net/PythonPrograms.txt
04-16.py
http://www.annedawson.net/PythonPrograms.txt
04-01.py
04-02.py
04-03.py
04-04.py
04-05.py
04-06.py
04-07.py
04-08.py
04-09.py
04-10.py
04-11.py
04-12.py
04-13.py
04-14.py
04-15.py
04-16.py