COMP1021
Introduction to Computer Science
Getting Started with Python
David Rossiter
Outcomes
• After completing this presentation, you are
expected to be able to:
1. Understand the history and some background
information of the Python programming
language
2. Briefly explain the difference between a
compiled and an interpreted program
3. Install Python and start using Python through
the command line tool and IDLE
COMP1021 Getting Started with Python Page 2
Computer Programming Languages
• Computer programming languages have been
developed over the last 50 years
• There are hundreds of them
• For this course we will use a language called
Python
COMP1021 Getting Started with Python Page 3
The Evolution of Programming Languages
• Where is Python
in all of that?!
• Do we need to know about all
those other languages? Thankfully, no!
• But once you know Python learning another
programming language is easy
Python
• Started by a guy who was bored during Christmas 1989
• He made a computer language with these qualities:
– a language just as powerful as other languages
– code that is almost as understandable as simple English
– suitable for everyday tasks, so you can quickly make a
useful program
– open source, so anyone can contribute to its development
COMP1021 Getting Started with Python Page 6
Guido van
Rossum
• He has been working
for Google up to 2012
• He is now working for
Dropbox
Why is it called Python?
• He called his language Python because
of his favourite TV comedy program,
‘Monty Python’s Flying Circus’
COMP1021 Getting Started with Python Page 7
Running a Program
• Most of the programs on
your computer are .exe files
• For example, if you run
Microsoft Word, it means
the file winword.exe is
being executed
• Microsoft Word is a program that has been compiled
into winword.exe, so it can be directly run by a
computer
COMP1021 Getting Started with Python Page 8
Running a Compiled Program
User
Program
• A computer can understand and directly run an exe file
COMP1021 Getting Started with Python Page 9
Executing a Python Program
• Python programs are a bit different, they have to
be ‘given’ to a Python interpreter for execution
Python User
source
code
Python
interpreter
myprogram.py python.exe
• We say that Python code is interpreted
• This is the most common way that Python is used
Python is Interpreted
• Interpreted means that each line of code is given
to the interpreter and executed, one by one
User
Python
source code
Python
interpreter
myprogram.py python.exe
• In this course we won’t look at the difference
between interpreting and compiling any further
Different Versions of Python
• There are two versions of Python being used: Python
version 2 and Python version 3
• We will use the more recent version, version 3
• Although Python version 2 is older, it is still used by
many people around the world (no-one uses version 1)
• Python 3.6 has been installed in all the CS department
labs and should be in all the computer barns
• You can run it virtually – details a few slides later
• You can install it in your own computer, see next slide
COMP1021 Getting Started with Python Page 12
How to Install Python 3.6?
• To install Python on your own PC/Mac system, you can
get the installation files from the COMP1021 web site:
PC users
Mac users
The ITSC Virtual Barn
• The ITSC virtual barn lets you access Python
(and other software) anywhere:
http://itsc.ust.hk/services/academic-teaching-
support/facilities/virtual-barn/overview/
• You can find Python 3.6 in the
‘Programming Software’ pool
After Installing • After installing, you will see
several options if you search
Python 3.6 for Python in the start menu
(These images are from a PC)
• Here is some documentation
about Python
– Probably you won’t need to
look at this, the COMP1021
notes and labs should be
enough
• Note - you probably won’t
see this in the CS labs, but
you will see it if you install
Python in your own
computer
Using Python
• Let’s look at how
we can start using
Python
• There are two ways
we will look at now
COMP1021 Getting Started with Python Page 16
Using Python
• Both options give
you a shell
The Basic Idea of Using a Python Shell
2. The shell 1. User types
passes things one line
whatever at a time, in the
you type Python shell The User
to Python
Python
interpreter
python.exe
3. The Python
interpreter 4. The interpreter outputs
executes the results, which are
whatever is shown in the shell
given to it
Using a Python Shell –
Some Simple
Python Code
>>> is generated by the shell,
it means ‘this is where your input is shown’
Using the
IDLE Environment
• The IDLE environment is better
• One reason is that colours are automatically used,
which is sometimes very helpful for understanding
• We’ll see other useful features of IDLE soon,
especially in the lab work that we’ll do