h01 (Chapter 1.11, 1.13 - 1.13.1, 1.14 - 1.15)

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

14 Terms

1
New cards
print("CS9")
CS9 = CS10
print(CS9)

Error Type

Runtime Error

2
New cards
$cs = 10
print($cs)

Error Type

Syntax Error

3
New cards
s = "UCSB"
print(s[4])

Error Type

Runtime Error

4
New cards
for x in "h00":
    print(x[0])
    print(None)
print("out of for loop")

Error Type

No Error

5
New cards
try:
    for i in range(5):
        x = i / (i-5)
except:
    print("EXCEPTION CAUGHT")
print("RESUMING EXECUTION")

Output

RESUMING EXECUTION

6
New cards
cs9 = "CS9"
try:
    for s in cs9:
        x = len(cs9) + s
    print("DONE LOOPING")
except:
    print("EXCEPTION CAUGHT")

Output

EXCEPTION CAUGHT

7
New cards

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

8
New cards

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.

9
New cards

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

10
New cards

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

11
New cards

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.

12
New cards

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__

13
New cards

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

14
New cards

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.