5th unit--classes and obj Flashcards

1
Q

py class with syn

A

*It is a user defined data structure that binds data members and methods into single unit
* Blueprint or object constructor for creating objects
* Class keyword is used to define it
Syn: class classname:
stmts

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

object-syntax

A
  1. We can use class name to create object
    syntax: obj= classname()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

__init()__ (3) eg

A
  1. built in function
  2. This **automatically executed an object of classes created **
  3. In Python every **object can have its own value for attributes of class **this can be achieved by in it method
  4. It is like a **constructor which allows class to hold objects with different values **
  5. We dont need to call the function like typical functions or methods … It is automatically executed when an object is created
  6. Eg: class classname:
    def __init__(obj, props_ _ _0):
    obj.prop= prop
    |
    |
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

self(4)

A
  1. Acts as this pointer in C++
  2. Self parameter is a reference to current instance of class
  3. Used to access variable that belongs to class
  4. We can name it anything we want but it should be only first place __init__(self, )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

pass

A

Class definition cannot be empty, But for some reasons if we don’t have Anything to declare we can put “pass” To avoid errors

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

Data abstraction hiding through classes

A
  1. Data abstraction refers to the process by which data and functions are defined in such a way that only essential details are provided to the outside world and implementation details are hidden
  2. Classes Follow data abstraction i.e. Provide the functionality of object or manipulation of object data and hiding implementation details of class or method to the outside entity
  3. Data encapsulation: Is also called as data hiding
    Wrapping up the data Into one unit
    – This prevents data modification accidentally by limiting access only to the variables and methods

    –organising the data and methods into structure that prevents data access by a functional method that is not specified in the class—- This ensures the integrity of data contained in the object
  4. Data encapsulation provides different access levels for the variables and members of function of class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Access levels

A

Public:
1. accessed by any function belonging to any class
2. Lowest level of data protection
Private:
1. accessed only by the class in which it is declared
2. Highest level of data protection
3. Prefixed by double _ _ eg: ** _ _ person**

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

built-in cls attri

A
  1. __dict__ Gifts dictionary contains class or objects
  2. __doc__ Provides documentation of an object (o/p–none)
  3. __name__ Name of the class
  4. __module__ Name of the model in which class/ obj it is defined
  5. __bases__ Returns base class or base class lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Class variable

A
  1. Class variables are declared inside the construction of class
  2. Since these variables are owned by class itself they are shared by class instances also
  3. These variables are defined inside a class just after declaration of class header before Declaring any method of constructor and other functions
    eg:
    #defining the class
    class Class_name:
    #declaring the variable in the class
    var = “xyz”
    #instantiating the class
    myObj = Class_name()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Object/instance variable

A

instantiating the class

  1. Variables that are owned by a class objects are called as object variables
  2. Unlike class variables object variables are defined inside the function

eg:
#defining the class
class Student:
# using the initializing function
def __init__(self, id, name, age):
self.id = id
self.name = name
self.age = age

dBase = Student(102, “Sam”, 13)
#printing the required values
print(“Roll Number of the Student:”, dBase.id)
print(“Name of the Student:”, dBase.name)
print(“Age of the Student:”, dBase.age)

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

Del()

A
  1. Initiate a object is created and delete is automatically called when an object is going out of scope
  2. Object goes out of scope when object is no longer used and its resources are occupied returned back to the system so that others can reuse them
  3. DEL keyboard also explicitly do the same

programme isnt the class work

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

cls attri

A

1.

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