Week 1
Week 1
Week 1
Introduction and overview.
Programming and Python Basics.
Course Information
2
Lab Assignments
• Students will attend weekly hands-on exercises during the lab session.
• There are 10 lab assignments to be completed during the weekly lab sessions.
• You will be graded for your performance and submission of your lab solutions.
• You must attend the lab session and upload your solution by the end of the
session to receive a grade.
• There are no make-ups for lab assignments. Special permission and medical
reports will not be accepted.
• You may not attend a lab other than the one to which you are registered.
3
Lab Grading and Attendance
• If you do not attend a lab, your grade for that lab will be zero.
• There are no make-up assignments for lab sessions, however in calculating your
lab average your lowest lab score will be discarded and your lab average will be
calculated using your top 9 lab scores.
• Students who do not attend the weekly lectures cannot receive full points for
the lab sessions.
• In order to receive full points for the lab assignments each week, you must
attend the lecture.
• Students who DO NOT attend the lecture but DO attend the lab session may
receive AT MOST 50% for the lab assignment.
4
Textbook
• Both books are open source and can be downloaded for free from the links given above.
5
What is Data Science?
6
Why Learn Programming?
7
What is Python
• A programming language is like any other language, it has a vocabulary and set of
grammatical rules for instructing a computer or computing device to perform
specific tasks.
• Python is a general-purpose programming language that can be used for a wide
variety of applications.
• Python is popular because there are many ready-made tools that are available
for data analysis.
8
Software
• For the course, we will be using the Anaconda Python 3.9 Distribution.
• Anaconda contains:
• Python: a programming language in which we write computer programs.
• We recommend that you install the Anaconda Python 3.9 distribution using the
instructions found at the following link: Anaconda Python
• When you download Anaconda, you will have access to the tools used in the
course: Python, Spyder and Jupyter.
10
Online Development Environment
• During the lab sessions you should use Spyder to complete your work.
• However, for practice outside the labs, if you are away from your
computer and want to practice Python, we recommend the online
tool, replit.com.
• Replit requires you to create an account however it is free to use.
11
First Python Commands
• A Python program is made up of one or more statements/commands, which are instructions
telling the computer to do something.
• Like in any language, statements must be meaningful and follow certain rules.
• When we type a command, the Python interpreter has to decide how to carry out the
command.
• If our command is not written correctly, the interpreter cannot understand what we are
asking, and will display an error message.
• Errors in the commands must be corrected for our statements to run (execute) correctly.
12
First Commands: Examples
• Step 1: Open the development environment.
• Step 2: Type the command(s).
• Step 3: Evaluate the results.
Try the following:
13
Things to Notice
• Whitespace characters:
• Include spaces, newlines, tabs and they make programs and commands easier to read.
• Notice in the examples, we put spaces before and after the arithmetic operators ( 3 + 5 )
• This is an example of using whitespace to improve readability.
• The python interpreter ignores these extra characters, as they are for the reader of the
program (us!) rather than the interpreter.
• With the spaces removed, the program would behave in the same way.
• Also notice that for multiplication, we use the ‘*’ symbol instead of 3 x 5.
• These are examples of the syntax rules of python, which we will discuss in
detail next week.
14
print() statement
• Python provides functions to carry out common tasks, the print
function is an example of this.
• The print() statement allows us to print messages to the console
window in our programs.
• print() can echo text strings, numbers or calculations.
• Text strings should be between single or double quotes.
• If we would like to output multiple values, we can separate them with
a comma.
15
First Commands: print()
• Try the following:
16
Printing Special Characters
• Sometimes we want to include characters in our output that have
special meaning.
• This includes characters such as quotes, newlines, etc.
• The table below shows a number of special characters in python.
Special Meaning
Character
\n New line character
\t Tab character
\\ Backslash character
\’ Single quote
\” Double quote
17
Printing Special Characters - Examples
Example 1:
Example 2:
18