Python is an object oriented programming language. Almost everything in Python is an object is simply a collection of data (variables) and methods (functions) that act on those data. A Class is like an object constructor, or a "blueprint" for creating objects. You can create many objects from the same class type.
Example :
A dog has states - color, name, breed as well as behaviors – wagging the tail, barking, eating. An object is an instance of a class.
Syntax of Class:
class Class_Name :
# statements
Example of Class:
class student :
name = " Tutor joe's "
age = 30
Syntax of Object:
object_name = class_name ( arguments )
Example of Object:
s = student ( )
The code you provided defines a class called "car" using the class keyword, and creates an empty class using the pass statement. It then creates an object of the class car called swift.
The type() function is used to check the type of the variable passed to it.
The isinstance() function is used to check if an object is an instance of a class.
class car(): pass a = 10 print(type(a)) print(type(car)) swift=car() print(isinstance(swift,car)) print(isinstance(a,int)) print(type(swift))To download raw file Click Here
<class 'int'> <class 'type'> True True <class '__main__.car'>
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions