Week2-4 Flashcards
What does the 0:.2f mean in this code:
“Floating point {0:.2f}”.format(4.456)
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.)
What does the lowercase d mean in:
‘Sam has {1:d} red balls’
The number outputted will be an Integer
What does the lowercase f mean in:
“Floating point {0:.2f}”
The outputted number will be a Floating Point number (i.e., a # with a decimal)
Given this code:
‘Sam has {1:d} red balls and {0:d} yellow balls’.format(12, 31)
What will the Output be?
Sam has 31 red balls and 12 yellow balls
Given: def times(x, y):
Which one is the function?
Which one is the argument?
‘times’ is the function
x and y are the arguments of the function
Given:
print(‘abc’):
Which one is the function?
Which one is the argument?
‘print’ is the function
‘abc’ is the function’s argument
T/F:
Integers are immutable
True
T/F:
Strings are immutable
True
T/F:
Lists are immutable
False
T/F:
Tuples are immutable
True
T/F:
Floats are immutable
True. Floating numbers cannot be changed
T/F:
Integers are mutable
Fals. Integers can be changed.
What is a docstring?
see Week 3 HW, first question
see Week 3 lecture Notes
What is ‘None’ in the Python language?
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.
if your function does not have a return statement, it’ll by default return a ____.
None (aka, NoneType)