You are on page 1of 13

DSA using Python

Classes and Objects

Saurabh Shukla (MySirG)


Agendas
-

① Class
② Attributes
③ Objects
⑥ Class object
⑤ _ _
init _
C) method
_

⑥ Types of methods
⑦ Types of variables
Real

%¥÷÷÷%÷÷
class

Object


Noun
Common Noun

.
Encapsulating
properties
An act
of combining
and methods related same

Encapsulation
object is known as

to implement
class is a way

encapsulation
Clad

class is a description of an object .

Chess Test :

# attributes

attributes ofan
• It defines various

object .

Defining a class is creating


a data type
Attributes
-

Attributes are member variables

and member functions

x and f- I
class Test :

are attributes
2C =
5

def fi c) :

# some code
Objects
instance of class

Object is an
a
.

Objects are of two types


Class object ☐± ☐

→☐
-

Instance object

'

tl = Test C)

t2 = Test C) ti and tz are instance

Test class
+I = Tests ] objects of
Class Object
-

Test vs Test C)

Test
☐→☐ Class object

has
class object
One class exactly one

but can have any number of instance

objects
Class Test :

Test clan
≠ ☐→☐ object

+ I = Test )
At

}
1- 2 =Test C)
Test C)
→ ☐ instance
+3 =
tz
Objects

☐ ☐
① clan object variables

② Instance obje
variables
.µ→gyJ
static variables
iinit__csMethod_
-

Class Test :

init C self ) :
def _
_
-
_

9=5
self .

b 6
self - =

init ( ti )
→ # _ _

Test C)
-
_

£1 =

and b
%→Ñ
a are instance object variables
Methods

Instance method
• static method
• class method
static variables
and instance variables

Test

☐→← static
variable

ti
p→t3← instance
variables
1- 2
D→g¥←←
Create a Employee
class with

attributes empid, name salary,

and also define methods to

access properties of Employee .

You might also like