COMPROG FINALS

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

1/18

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.

19 Terms

1
New cards

Class

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

  • Creating a new — creates a new type of object, allowing new instances of that type to be made. 

  • Each — instance can have attributes attached to it for maintaining its state. 

  • — instances can also have methods (defined by their class) for modifying their state.

  •  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. 

2
New cards

Class

like a blueprint for an object

  • — are created by keyword —.

  • Attributes are the variables that belong to a —. 

  • Attributes are always public and can be accessed using the dot (.) operator. Eg.: My —.Myattribute 

3
New cards

Object

  • is an instance of a Class. 

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

4
New cards

State

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

5
New cards

Behavior

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

6
New cards

Identity

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

7
New cards

Declaring Class Objects


  • also known as instantiating a class

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

  • All the instances share the attributes 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. 

8
New cards

Self Parameter


  • 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.

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

  • Here we change the self to the word cats and the output will be the same.

9
New cards

Pass Parameter

  • The program’s execution is unaffected by the —statement’s inaction. 

  • It merely permits the program to skip past that section of the code without doing anything. 

  • It is frequently employed when the syntactic constraints of Python demand a valid statement but no useful code must be executed.

10
New cards

__init__() method

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

  • Like methods, a constructor also contains a collection of statements(i.e. instructions) that are executed at the time of Object creation. 

  • It runs as soon as an object of a class is instantiated. 

  • The method is useful to do any initialization you want to do with your object.

11
New cards

__del__() method 


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

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

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

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

12
New cards

Automatic cleanup

  • 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. 

13
New cards

Consistent behavior

  • 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.

14
New cards

Easy to use

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

15
New cards

Supports object-oriented programming

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

16
New cards

Helps with debugging

  • 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.

17
New cards

_str_() method

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

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

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

  • You can alter how objects of a class are represented in string

18
New cards

Instance Variables

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

  • — 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. 

19
New cards

2 ways to define instance variables

  • Using a constructor 

  • Using Getters and Setters (normal way)