LESSON 3 Flashcards

1
Q

__ is a user-defined blueprint or prototype from which objects are created. __ provide a means of bundling data and functionality together

A

class, Classes

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

Creating a new class creates a new type of ___, allowing new instances of that type to be made.

A

object

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

creates a user-defined data structure, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class.

A

Class

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

is like a blueprint for an object

A

Class

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

Some points on Python class:

A

● Classes are created by keyword class.
● Attributes are the variables that belong to a class.
● Attributes are always public and can be accessed using the dot (.) operator. Eg.: My class.Myattribute

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

An ___ is an instance of a Class

A

Object

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

A class is like a ___while an instance is a ___ of the class with actual values

A

blueprint, copy

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

It is represented by the methods of an object. It also reflects the response of an object to other objects.

A

Behavior:

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

● An object consists of:

A

State:
Behavior:
Identity:

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

It is represented by the attributes of an object. It also reflects the properties of an object

A

State:

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

DECLARING CLASS OBJECTS is also known as

A

instantiating a class

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

It gives a unique name to an object and enables one object to interact with other objects

A

Identity:

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

When an object of a class is created,
the class is said to be

A

instantiated

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

All the ___ share the attributes
and the behavior of the class. But the
values of those attributes, i.e. the state
are __for each object.

A

instances, unique

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

A __ __ may have any number of
instances.

A

single class

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

When we call a method of this object as pyobject.method(arg1, arg2), this is automatically converted by Python into PyClass.method(myobject, arg1, arg2) – this is all the special self is about.

A

Self Parameter

15
Q

does not require for you to name it “self”. You can use any other name instead of it.

A

Self Parameter

16
Q

is similar to constructors in C++ and Java. Constructors are used to initializing the object’s state.

A

_ init _() method

17
Q

In Python, ___ are not needed as much as in C++ because Python has a garbage collector that handles memory management automatically

A

destructors

17
Q

is known as destructor, which are called when an object gets destroyed.

A

_ del _() method

18
Q

It is called when all references to the object have been deleted i.e when an object is garbage collected.

A

_ del _() method

19
Q

The destructor was called ____ or when all the references to object are deleted, i.e when the reference count becomes zero, not when object went out of scope.

A

after the program ended

20
Q

Advantages of using destructors in Python

A

Automatic cleanup
Consistent behavior
Easy to use
Supports object-oriented programming
Helps with debugging

21
Q

Destructors provide __ ___of resources used by an object when it is no longer needed. This can be especially useful in cases where resources are limited, or where failure to clean up can lead to memory leaks or other issues.

A

Automatic cleanup

21
Q

Destructors ensure that an object is properly cleaned up, regardless of how it is used or when it is destroyed. This helps to ensure ___ ____ and can help to prevent bugs and other issues.

A

Consistent behavior

22
Q

Destructors are easy to implement in Python and can be defined using the __del__() method.

A

Easy to use

23
Q

Destructors are an important feature of object-oriented programming and can be used to enforce encapsulation and other principles of object-oriented design.

A

Supports object-oriented programming

24
Q

Destructors can be useful for debugging, as they can be used to trace the lifecycle of an object and determine when it is being destroyed

A

Helps with debugging

25
Q

is used to define how a class object should be represented as a string.

A

_ str _() method

26
Q

It is often used to give an object a human-readable textual representation, which is helpful for logging, debugging, or showing users object information.

A

_ str _() method

27
Q

are for data, unique to each instance and class variables are for attributes and methods shared by all instances of the class.

A

Instance variables

28
Q

are variables whose value is assigned inside a constructor or method with self whereas class variables are variables whose value is assigned in the class.

A

Instance variables

29
Q

We can define instance variables within 2 ways

A

● Using a constructor
● Using Getters and Setters (normal way)