Introduction To Python
Introduction To Python
Tharaka Ilayperuma
MYSELF
Qualifications: PhL as well as PhD in Computer and Systems Sciences from Stockholm
University, Sweden
Roles: University Lecturer (21 years +), Systems developer (two systems)
What we will cover in this course?
Editors are what you write Python instructions with Not all editors are equal!
So that they can be interpreted by the Python interpreter
This happens when you run your program
Find one that suits you…
(or at least your current purposes)
What is programming?
Why Python?
So that you know the basics to start writing a simple Python program!
Assignment details
You will be given several tasks organised into three assignments to submit
When you pass the course you will get 20 level 4 credits – This will be a good
opportunity to improve your skill portfolio at free of charge!
What is programming?
Use proper spacing to increase the readability (within and between different blocks of statements)
Detecting and correcting errors in
your program
Carefully read what the error is about and in which line
You may not be the only one who may be having some programming problem. So just
Google your error and try to get help
Why Python?
Python is
Easy to use
Powerful
Versatile
3) Do some processing
4) Output results
Basic structure of the program..
Python variables are dynamically assigned and their type doesn’t need to
be pre-declared
coin = "Heads!" OR coin = str (Heads!) A(string - str)
These are 3 examples of built-in
https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
types in Python
- bool
- tuple, list, dict average = 5.6 A(floating point number - float)
https://docs.python.org/3/library/functions.html#float
Write a Python program to assign your name to a variable and display it using the print()
function.
Arithmetic operators
Python supports the standard arithmetic operators:
* multiply
/ divide
% remainder
+ add
- subtract
Python also supports operators such as <,>, <=, >=, ==, !=, =
Exercise 2
Write a simple Python program to assign two integers to two variables and perform
addition, multiplication, subtraction, and any other arithmetic operation that we
discussed in the previous slide on them and display the results, separately.
Operator precedence
Operators have precedence which determines the order in which they are evaluated:
operators with the same order of precedence are evaluated from left to right
[*, /, %, //] are evaluated before [+, -]
We looked at
• installing Python and using a Python editor
• Programming and debugging tips
• Overview of Python and it’s uses
• Data types and operators in Python
Questions?