Week2-4 Flashcards

1
Q

What does the 0:.2f mean in this code:

“Floating point {0:.2f}”.format(4.456)

A

The 2 is the number of digits to display after the decimal point.
The f means that it will be a “floating point” number (i.e. it will have a decimal.)

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

What does the lowercase d mean in:

‘Sam has {1:d} red balls’

A

The number outputted will be an Integer

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

What does the lowercase f mean in:

“Floating point {0:.2f}”

A

The outputted number will be a Floating Point number (i.e., a # with a decimal)

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

Given this code:
‘Sam has {1:d} red balls and {0:d} yellow balls’.format(12, 31)

What will the Output be?

A

Sam has 31 red balls and 12 yellow balls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
Given:
def times(x, y):

Which one is the function?
Which one is the argument?

A

‘times’ is the function

x and y are the arguments of the function

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

Given:
print(‘abc’):

Which one is the function?
Which one is the argument?

A

‘print’ is the function

‘abc’ is the function’s argument

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

T/F:

Integers are immutable

A

True

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

T/F:

Strings are immutable

A

True

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

T/F:

Lists are immutable

A

False

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

T/F:

Tuples are immutable

A

True

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

T/F:

Floats are immutable

A

True. Floating numbers cannot be changed

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

T/F:

Integers are mutable

A

Fals. Integers can be changed.

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

What is a docstring?

A

see Week 3 HW, first question

see Week 3 lecture Notes

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

What is ‘None’ in the Python language?

A

None is a ‘datatype’ in Python whose purpose to basically representing a null value, or ‘nothing’. So if your function does not have a return statement, it’ll by default return a None.

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

if your function does not have a return statement, it’ll by default return a ____.

A

None (aka, NoneType)

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

the None datatype is aka:

A

NoneType

17
Q

arguments are aka:

A

parameters

18
Q

List the datatypes in Python:

A
int,
float,
complex,
bool,
str,
NoneType
19
Q

Given this code/input:

> > > L = [1]
L[:0] = [2, 3, 4]
L

What is the output?

A

[2, 3, 4, 1]

20
Q

Given this code:

> > > L = [1, 2, 3]
L[1:2] = [4, 5]
L

What is the output?

A

[1, 4, 5, 3]

21
Q

Given this code:

> > > L = [1, 4, 5, 3]
L[1:1] = [6, 7]
L

What is the output?

A

[1, 6, 7, 4, 5, 3]

22
Q

Given this code/input:

> > > L = [1, 6, 7, 4, 5, 3]
L[1:2] = []
L

What is the output?

A

[1, 7, 4, 5, 3]

23
Q

Given this input:

> > > L = [‘eat’, ‘more’, ‘SPAM!’]
L.append(‘please’)
L

What is the output?

A

[‘eat’, ‘more’, ‘SPAM!’, ‘please’]

24
Q

the .sort command sorts in [ascending / descending] order

A

ascending

25
Q

Given this input:

> > > L = [‘abc’, ‘ABD’, ‘aBe’]
L.sort() # Sort with mixed case
L

What is the output?

A

[‘ABD’, ‘aBe’, ‘abc’]

26
Q

Given this input:

> > > L = [1, 2, 3, 4, 5]
L.pop()
L

What is the output?

A

[1, 2, 3, 4]

27
Q

Given this input:

> > > [1, 2, 3, 4]
L.reverse()
L

What is the output?

A

[4, 3, 2, 1]

28
Q

Give the code that is missing below:

> > > [1, 2, 3, 4]
_________
L
[4, 3, 2, 1]

A

L.reverse()

29
Q

Given this input:

> > > L = [‘spam’, ‘eggs’, ‘ham’, ‘toast’]
del L[0]
L

What is the output?

A

[‘eggs’, ‘ham’, ‘toast’]

30
Q

Given this input:

> > > L = [‘Already’, ‘got’, ‘one’]
L[1:] = []
L

What is the output?

A

[‘Already’]