ARcPSD| 7048722
Lab01 - Foundations of Data Science: Expressions & Python
Basics
Expressions
. You can’t learn technical subjects without hands-on practice, so labs are an important part of the course.
Before we get started, there are some administrative details.
The weekly lab session has two components: questions and discussion (not using the computer) about
recent material, and a lab assignment (like this one!) that develops skills with computational and inferential
concepts. These lab assignments are a required part of the course and will be released on the day of the day.
submit the lab via blackboard and have a faculty or a TA check you offas JPNYB file, if you
submit pdf make sure the complete file saved.
Today’s lab In today’s lab, you’ll learn how to:
1. navigate Jupyter notebooks (like this one);
2. write and evaluate some basic expressions in Python, the computer language of the course;
3. call functions to use code other people have written; and 4. break down Python code into smaller parts
to understand it.
This lab covers parts of Chapter 3 of the online textbook. You should read the examples in the book,
but not right now. Instead, let’s get started!
2 1. Jupyter notebooks
This webpage is called a Jupyter notebook. A notebook is a place to write programs and view their results,
and also to write text.
2.1 1.1. Text cells
In a notebook, each rectangle containing text or code is called a cell.
Text cells (like this one) can be edited by double-clicking on them. They’re written in a simple format
called Markdown to add formatting and section headings. You don’t need to learn Markdown, but you might
want to.
After you edit a text cell, click the "run cell" button at the top that looks like | or hold down shift + return
to confirm any changes. (Try not to delete the instructions of the lab.)
Question 1.1.1. This paragraph is in its own text cell. Try editing it so that this sentence is the last
sentence in the paragraph, and then click the "run cell" | button or hold down shift + return. This sentence,
for example, should be deleted. So should this one.
1
, lOMoAR cPSD| 70487227
2.2 1.2. Code cells
Other cells contain code in the Python 3 language. Running a code cell will execute all of the code it
contains.
To run the code in a code cell, first click on that cell to activate it. It’ll be highlighted with a little green
or blue rectangle. Next, either press | or hold down shift + return.
Try running this cell:
In [1]: print("Hello, World!") Hello, World!
And this one:
In [2]: print("\N{WAVING HAND SIGN}, \N{EARTH GLOBE ASIA-AUSTRALIA}!")
,!
The fundamental building block of Python code is an expression. Cells can contain multiple lines with
multiple expressions. When you run a cell, the lines of code are executed in the order in which they appear.
Every print expression prints a line. Run the next cell and notice the order of the output.
In [7]: print("First this line is printed,") print("then the whole \N{EARTH
GLOBE ASIA-AUSTRALIA}") print("and then this one.")
First this line is printed, then the
whole and then this one.
Question 1.2.1. Change the cell above so that it prints out:
First this line, then the
whole , and then this
one.
Hint: If you’re stuck on the Earth symbol for more than a few minutes, try talking to a neighbor or a
staff member. That’s a good idea for any lab problem.
2.3 1.3. Writing Jupyter notebooks
You can use Jupyter notebooks for your own projects or documents. When you make your own notebook,
you’ll need to create your own cells for text and code.
To add a cell, click the + button in the menu bar. It’ll start out as a text cell. You can change it to a code
cell by clicking inside it so it’s highlighted, clicking the drop-down box next to the restart () button in the
menu bar, and choosing "Code".
Question 1.3.1. Add a code cell below this one. Write code in it that prints out:
A whole new cell!
2