CLASS AND OBJECT IN PYTHON

GOCOURSE


 

Class

In python a class is a type of object oriented programming. It is a container for dta and functions. A Class is like an object constructor, or a "blueprint" for creating objects. To create a class, use the keyword class. It is a Collection of objects is called class. It is a logical entity.

Syntax: 

class Classname:
#statement1
......
......
#statement n

Object

Object is a instance of a class.  you can create multiple objects with same behavior, instead of repeating. Object is also a copy of the class.

write a class and object program 

Program:


  class bike:
    name="hero"
    model=2022
    def function1(self):
      print("bike name and model")
      print(self.name)
      print(self.model)
  obj=bike()
  obj.function1()


Output:


  bike name and model
  hero
  2022






More topic in Python

Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send