Representing data: Variables and Types

Website for the UCSB Data Science Capstone Preparation Workshop

Representing data: Variables and Types

Learning Goals

Numeric types

Text

Assume year is 2021, and budget is set to "$1,200,000". What is the output of the following? print("The budget in", year, "was", budget)

Numbers vs. text

The string '2021' (with quotes) is fundamentally different from the integer 2021 (without quotes). The ‘2021’ string is a sequence of the characters '2', '0', '2', and '1' arranged in a certain order, whereas 2021 represents the integer value two-thousand twenty-one. You can do arithmetic with the numeric types but they do not work with text.

What do you get if you run the following? Why?

print('2021' * 2)
print(2021 * 2)

Collections

names = [] # same as list()
names.append(‘Sarina’)
names.append(‘Lia’)
names.sort()
print(names)

# first name on the list
names[0]
# second name on the list
names[1]
print(“Name 1”, names[0])
print(“Name 2”, names[1])

A list and a dictionary

Important notes and terminology:

Check your understanding