A class is a user-defined blueprint or prototype from which objects are created. Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state.
Refer to the below article to know about the basics of Python classes.
An Object is an instance of a Class. A class is like a blueprint while an instance is a copy of the class with actual values.
To understand objects let’s consider an example, let’s say there is a class names dog that contains certain attributes like breed, age, color and behaviors like bark, sleep and eat. An object of this class is like an actual dog, let’s say a dog of breed pug who’s seven years old. You can have many dogs to create many different instances, but without the class as a guide, you would be lost, not knowing what information is required.
An object consist of:
- State: It is represented by attributes of an object. It also reflects the properties of an object.
- Behavior: It is represented by methods of an object. It also reflects the response of an object with other objects.
- Identity: It gives a unique name to an object and enables one object to interact with other objects.
Declaring Objects (Also called instantiating a class)
When an object of a class is created, the class is said to be instantiated. All the instances share the attributes and the behavior of the class. But the values of those attributes, i.e. the state are unique for each object. A single class may have any number of instances.
mamal I'm a mamal I'm a dog
- Reading Python File-Like Objects from C | Python
- File Objects in Python
- Barrier Objects in Python
- Python Classes and Objects
- Timer Objects in Python
- Print objects of a class in Python
- Session Objects - Python requests
- Byte Objects vs String in Python
- Mutable vs Immutable Objects in Python
- Flattening JSON objects in Python
- Built-in Objects in Python-builtins
- Python | Counter Objects | elements()
- Python: Difference between Lock and Rlock objects
- Python | Unit Test Objects Patching | Set-2
- Python | Unit Test Objects Patching | Set-1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.