Oops
Oops
ANS-a class is a blueprint for creating objects, encapsulating data (attributes) and behavior
(methods) into a single entity.
Creating Classes and Objects-To define a class in Python, use the class keyword. An object is
an instance of a class. When you create an object, you can access the data and methods
defined within that class.
class Dog:
self.name = name
self.age = age
my_dog = Dog("Buddy", 5)
ANS- Attributes: These are variables defined within a class to hold data. They can be class
attributes (shared by all objects) or instance attributes (specific to each object).
Methods: These are functions defined within a class that describe the behaviors or actions
of the object. They usually take self as the first parameter, referring to the current instance.
• Marking variables as "private" using a leading underscore (_) or double underscore (__),
indicating they shouldn't be accessed directly from outside the class.
• Providing methods (getter and setter functions) to access and modify these variables,
enabling controlled access.