Website for the UCSB Data Science Capstone Preparation Workshop
int()
float()
str()
\n
and \t
)\n
is a newline character; technically, it consists of two characters (\
and n
) but together are considered by the Python interpreter as a single character. Same with a tab character \t
.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)
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)
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])
Important notes and terminology:
[
and ]
.
test_list = [ ]
,
test_list = ['Enterprise', 3.14159]
test_list[0]
{
and }
.
test_dict = { }
:
value pairs, which are separated by commas ,
test_dict = {'Enterprise' : 3.14159 }
test_dict['Enterprise']