We are well known Python is Object Orientd Programming Language.
class represents a group of similar objects to represents a classes
in python user-defined datatype.
A class is describe all the properties of a datatype,and
object is entity created according to that discription.
class is a keyword used to create a class.
class: #statement #statement #statementExample
class SmallCode: x="Small Code" print(SmallCode)
<class '__main__.SmallCode'>
Object is a real world,physical entity such as pen, computer, mobile, table, keyboard, mouse,book etc. It is also
instance of a class.
We can create zero or more object as per requirement.
Difference between Object and class
Class |
Object |
---|---|
Class is a blueprint or template from which objects are created. |
Object is an instance of a class. |
It is a group of similar objects. |
It is a real world entity such as mobile,car,book,laptop,chair etc. |
It doesn't allocated memory when it is created. |
It allocates memory when it is created. |
Class is declared once. |
We can create zero or more object as per requirement. |
Syntaxclass class_name: #statement |
Syntaxobject_var=class_name(value_if_any) |
Example
class sc: x="SmallCode" |
Example
class sc: x="SmallCode" obj=sc() print(obj.x) |