Python 1 2 Flashcards

1
Q

What does one row represent in a tabular dataset?

A

a single item/observation in your collection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does one column represent in a tabular dataset?

A

a single piece of information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What shape does tabular data take?

A

a rectangle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the difference between = and == in Python?

A

= assigns a value to a variable, == tests whether two items are the same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you write a multi-line string in Python?

A

””” wrap it in three quotes “””

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you write a comment in Python?

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the rules for Python variable names?

A

can use any upper/lowercase character, number, or _

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the function to check what Python type something is?

A

type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you make a string with ‘my qb is Tom Brady’ using f strings if ‘Tom Brady’ was in a variable called name?

A

f’my qb is {name}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

(Python) What type of a variable is (1 == 2)?

A

bool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

(Python) What is the value of (1 == 2)?

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

(Python) What is the difference between variables and strings in terms of quotation marks?

A

strings always have quotation marks; variables never do

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

(Python) How would you refer to the first element in a list named my_list?

A

my_list[0]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

(Python) How would you refer to the last element in a list named my_list?

A

my_list[-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

(Python) How would you refer to the first two elements in a list named my_list?

A

my_list[0:2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

(Python) What is the name for the part in brackets in my_list[0:2]?

A

a slice

17
Q

(Python) How many items does my_list[:n] return?

A

n

18
Q

(Python) What is a list surrounded by?

A

square brackets

19
Q

What is a Python dict?

A

a collection of key, value pairs

20
Q

(Python) What is a dict surrounded by?

A

curly brackets

21
Q

(Python) How would you access 1 in my_dict = {‘a’: 1, ‘b’: 2}?

A

my_dict[‘a’]

22
Q

(Python) How would you change ‘a’ to 0 in my_dict = {‘a’: 1, ‘b’: 2}?

A

my_dict[‘a’] = 0

23
Q

(Python) How would you add a new item ‘c’ = 3 in my_dict = {‘a’: 1, ‘b’: 2}?

A

my_dict[‘c’] = 3

24
Q

What is a loop in Python?

A

a way to do something for every item in a collection

25
Q

(Python) What does this code do? for x in my_roster_list: print(x)

A

prints the values of my_roster_list

26
Q

(Python) What is the default behavior when looping over a dict?

A

to loop over the keys only

27
Q

(Python) What do you have to your dict to loop over the key and value in a dict?

A

.items()

28
Q

When want to modify one list to get another list you should be thinking what?

A

a list comprehension

29
Q

(Python) What is the general form of a list comprehension?

A

[… for … in … if …]

30
Q

(Python) How would you turn mylist = [‘a’, ‘b’, ‘c’] into [‘A’, ‘B’, ‘C’] using list comprehensions?

A

[x.upper() for x in mylist]

31
Q

(Python) What would type([x*2 for x in [1, 2, 3]) return?

A

list

32
Q

(Python) What is [x*2 for x in [1, 2, 3]] called?

A

list comprehension

33
Q

(Python) How would you turn mydict = {‘a’: 1, ‘b’: 2} into {‘A’: 2, ‘B’: 4} using a dict comprehension?

A

{key.upper(): value*2 for key, value in mydict.items()}

34
Q

(Python) How would you turn mydict = {‘a’: 1, ‘b’: 2} into a list [1, 2] using list comprehensions?

A

[x for _, x in mydict.items()]

35
Q

What is the keyword to create a function in Python?

A

def

36
Q

(Python) Take the code: def over_100_total_yds(rush_yds, rec_yards): return rush_yds + rec_yards > 100 What are the names of the function arguments?

A

rush_yds, rec_yards

37
Q

(Python) Take the code: def over_100_total_yds(rush_yds, rec_yards): return rush_yds + rec_yards > 100 What is the function name?

A

over_100_total_yds

38
Q

What is the function name? over_100_total_yds (Python) Take the code: def over_100_total_yds(rush_yds, rec_yards): return rush_yds + rec_yards > 100 What type does the function return?

A

bool