Classes and Objects in Python
Classes and Objects in Python
OBJECTS IN
PYTHON
Nura 9G
╰► WHAT ARE CLASSES AND OBJECTS IN
Python Classes :
PYTHON?
A class is considered as a blueprint of objects. We can think of the class as a sketch
(prototype) of a house. It contains all the details about the floors, doors, windows, etc.
Based on these descriptions we build the house. House is the object.
Since many houses can be made from the same description, we can create many objects
from a class.
Python Objects :
An object is simply a collection of data (variables) and methods (functions). Similarly, a
class is a blueprint for that object.
Classes
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.
Objects
A python is an object-oriented programming language. Almost
everything in Python is considered as an object. An object has its own
properties(attributes) and behavior(methods).
A class is a blueprint of the objects or can be termed as object
constructor for creating objects.
One class can have many objects and value of properties for different
objects can be different.
╰► ADVANTAGES AND
DISADVANTAGES OF CLASSES
Advantages Disadvantage
- It’s very flexible
s
- This lacks structure: it's harder to look at the
- The class is defined without any members code and decide which members the class will
- Any function can decide which fields to add have
- Different invocations can create objects of this - It's also less straightforward to get such an
class, and populate them in different ways (so, object, and iterate over the members
simultaneously, you could have objects of the - The class is an extreme case of no
same class with different members). encapsulation.
- Classes provide an easy way of keeping the data - There is a potential for exhaustion, as they
members and methods together in one place can be in
which helps in keeping the program more constant interaction in an unnatural way with
organized. the teacher.
- Using classes also provides another functionality - It can be difficult to measure progress without
of this object-oriented programming paradigm, other students to compare with and the
that is, inheritance. possible lack of a syllabus.
- There can be a lack of individual study time.
╰► ADVANTAGES AND
DISADVANTAGES OF OBJECTS
Advantages Disadvantage
- Productivity of software development increased -
s
- Steep expectation to learn and adapt
Software maintenance improved - Bigger program size
- Quicker improvement - More slow projects
- Cost of development lowered - Not appropriate for a wide range of issues -
- Good quality software Size is larger than other programs
- We can reuse the code multiple times using class - It required a lot of effort to create
- Inherit the class to subclass for data redundancy - It is slower than other programs
- It is easy to maintain and modify - It is not suitable for some sorts of problems -
- It maintains the security of data It takes time to get used to it.
- Low-cost development
Define Python Class
We use the 「 class 」 keyword to create a class in Python. For example,
Here,
Here, bike1 is the object of the class. Now, we can use this object to access the
class attributes.
THANKY
OU!