w7 Flashcards

(15 cards)

1
Q

what is a class

A

class is a blueprint for creating objects. Objects are instances of classes that can contain both data (called attributes) and functions (called methods)

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

what is an instance

A

an individual object of a certain class

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

Procedural vs Object-Oriented Programming

A

Procedural - focuses on functions and variables separately
Object-Oriented - groups related functions and variables into “units” (objects

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

what does __init__ do

A

is called automatically to initialise object attributes when its created
- used for assigning values to instance/object properties

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

what does __str__ do

A

returns a user friendly string that reps an object

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

what does __add__ do

A

meaning of obj1 + obj2

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

what does __eq__

A

means obj1 == obj2

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

what does __sub__ mean

A

obj1 - obj2

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

what does __mul__ mean

A

means obj1 * obj2

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

whats Polymorphism

A

Refers to the ability of some bit of code to handle different data types

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

whats the polymorphic operator and what can it handle

A

’+’ is the polymorphic operator
it handles ints, strings, floats, lists

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

whats the polymorphic function and what can it handle

A

“len”
handles any object with a __len__ method

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

What is a method

A

a special kind of function that is defined in a class definition

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

repr() vs str() purpose

A

repr() makes the object into the string
str() demonstrates the string to a user

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

what is the polymorphic construct and what does it handle

A

for member in collection
handles any iterable

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