Relation between class and object in python 3.9.1

Spread the love

class and object in python 3.9.1

  • A class is a blueprint from which you can
    create the instance (object).
  • object is simply a collection of data (variables)
    and methods (functions) that act on those data.
  • classes have logical existence. – classes have physical existence.
  • A class doesn’t any memory space when
    created. (Also read Enumerate in python)
  • An object takes up the memory when it is
    created by the programmer.
class and object in python 3.9.1
class and object in python 3.9.1
Example:
- Creating a class name person.
Class person:
Def__init__(self, name, age, gender):
Self.name = name
Self.age = age
Self.gender = gender
P1 = person(‘Sachin’, 22, ‘male’)
Print(p1.name)
Print(p1.age)
Print(p1.gender)

Output:
Sachin
22
male
- creating an object in class name person.
Class person:
Def__init__(self, name, age, gender):
Self.name = name

Self.age = age
Self.gender = gender
Def myfunc(self):
Print(‘my name is’ + self.name)
Print(p1.name)
Print(p1.age)
Print(p1.gender)
P1.myfunc()

Output:
My name is Sachin.

Summary :

In this article we saw Relation between class and object in python 3.9.1 so about this article you have any query then free to ask me

Also see :

String Function in python

Break, Pass in python

sachin Pagar

I am Mr. Sachin pagar Embedded software engineer, the founder of Sach Educational Support(Pythonslearning), a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Reply