1/13
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
print("CS9")
CS9 = CS10
print(CS9)Error Type
Runtime Error
$cs = 10
print($cs)Error Type
Syntax Error
s = "UCSB"
print(s[4])Error Type
Runtime Error
for x in "h00":
print(x[0])
print(None)
print("out of for loop")Error Type
No Error
try:
for i in range(5):
x = i / (i-5)
except:
print("EXCEPTION CAUGHT")
print("RESUMING EXECUTION")Output
RESUMING EXECUTION
cs9 = "CS9"
try:
for s in cs9:
x = len(cs9) + s
print("DONE LOOPING")
except:
print("EXCEPTION CAUGHT")Output
EXCEPTION CAUGHT
Even though methods are similar to functions, briefly state what makes a method different than a function.
Methods differ because they involve an object and operate on its data. For example, count, append, and insert are examples of methods that can be called on objects like lists
The reading states "the first method that all classes should provide is the constructor". Briefly (in one sentence) state what the purpose of the class' constructor is.
The purpose of the class' constructor is to provide the values, either default or specified, of the object when it is constructed through the parameter list.
What is the name of the constructor method when defining it in a class (just the name will do without including any parameters or parenthesis)?
init
To create an instance of a class, we must invoke the constructor, but we never directly invoke the constructor method directly. Briefly (in one sentence), state what we need to do in order to create an instance of a class?
In order to create an instance of a class, we can use the class' name and pass real values for the state
A class' constructor always has the self parameter listed as the first formal parameter and is not used when actually creating an instance of the class.
Briefly (in one sentence) state what the purpose of the self parameter is.
The purpose of the self parameter is to represent the current object that we are calling the method on.
What is the method name to convert an object to a string (just the name will do without including any parameters or parenthesis)?
Please be EXACT with your answers (proper capitalization, spacing, etc).
__str__
The == operator can be used to compare two objects. By default, briefly state (in one sentence) what == is comparing?
By default, == is a equality operator that evaluates to a Boolean value, which is implemented through the eq method and it compares two objects. (True if they are the same and False otherwise).
Equal by value, not specifically equal by reference
The reading states we can check for deep equality by overwriting the __eq__ method. Briefly (in one sentence) state what deep equality means.
Deep equality means that there is equality by the same value not the same reference.