Lec02 PythonIntro_t
Lec02 PythonIntro_t
Introduction to
Programming in Python
Marianne Morris
marims@ualbert
a.ca
How to use the audio
and
the slide animations
Please turn up your device speakers
together
and run the slides in presentation mode
Click on the play button of the audio
icon as soon as a new slide is up
The play button of the audio icon will
appear when you wave the mouse over
the audio icon and will look like the
following picture:
How to use the audio
and
the slide animations
Slide animations run automatically in a timed
together
sequence regardless of whether the audio is
played or not
print("Hello, World!")
While statements
For statements
If statements
Important statements
Expressions
An expression is a combination of
values, variables, operators, and
calls to functions.
e.g., print(2+3)
Expressions need to be evaluated.
The interpreter evaluates the
expression and displays the result.
Operators
Arithmetic
+, -, *, /, //, **, %
Relational
<, >, <=, >=, !=, ==
Boolean
not, and, or
Arithmetic operators in
Python
Addition +
Subtraction -
Division
Integer //
Real numbers /
Multiplication *
Remainder %
Exponent **
Order of Operations
print(2 + 3 * 5)
float(…)
converts the data to a float
str(…)
converts the data to a string
Check
What’s the output of the following
statement?
print( int(55.785) )
Output:
55