LESSON 3 Flashcards

1
Q

_______
user-defined ______ or prototype from which objects are created.

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

provide a means of _______ and functionality together.

A
  • Classes
  • Bundling data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

are variables that belong to a class

A

Attributes

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

are always _____ and can
be accessed using the dot (.) operator.

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

is an instance of a Class

A

Object

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

like a blueprint while an instance is
a copy of the class with actual values

A

Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
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
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
9
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
10
Q

DECLARING CLASS OBJECTS
(also known as instantiating a class)

A

When an object of a class is created,
the class is said to be instantiated.
● Alltheinstancessharetheattributes
and the behavior of the class. But the values of those attributes, i.e. the state are unique for each object.
● A single class may have any number of instances.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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

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

The Self Parameter does not require for you to name it “______”. Other wise? __________You can use _______ instead of it.

A
  • Self
  • any other name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  • The program’s execution is unaffected by the pass statement’s inaction.
  • It merely permits the program to skip past that section of the code without doing anything.
A

Pass Parameter

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

syntactic constraints of Python demand a valid statement but no useful code must be executed.

A

Pass Parameter

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

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

A

_ init _() method

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

The__init__method is similar to constructors in ____ and _____.

A
  • C++ and Java
16
Q

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

A

_ del _() method

17
Q

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

A

Python

18
Q

when the reference count becomes zero, not when object went out of scope.

A

_ del _() method

19
Q

Advantages of using destructors in Python: _ del _() method

A
  • Automatic cleanup
  • Consistent behavior
  • Easy to use
  • Supports object-oriented programming
  • Helps with debugging
20
Q

Destructors provide automatic cleanup 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 consistent behavior 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

Easy to use: Destructors are easy to implement in Python and can be defined using the _______

A

__del__() method

24
Q

define how a class object should be represented as a string.

A

_ str _() method

25
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

26
Q

When a class object is used to create a string using the built-in functions ____ and ____, the __str__() function is automatically used.

A
  • print() and str()
27
Q

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

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