Python Tutorial
Python Variable
Python Operators
Python Sequence
Python String
Python Flow Control
Python Functions
Python Class and Object
Python Class Members (properties and methods)
Python Exception Handling
Python Modules
Python File Operations (I/O)
Object Orientation is a programming paradigm that emphasizes the use of objects, which are instances of classes, to represent and manipulate data. In object-oriented programming, data and the methods that operate on that data are encapsulated into objects, which can communicate with each other to perform complex tasks.
Python is an object-oriented programming language, which means that it supports the creation and manipulation of objects. In Python, you define a class using the class
keyword, and you create an object of that class using the class name followed by parentheses.
Here's an example of a simple Python class:
class MyClass: def __init__(self, value): self.value = value def double_value(self): return self.value * 2
In this example, we define a class called MyClass
with an __init__
method and a double_value
method. The __init__
method is a special method that is called when a new instance of the class is created. The double_value
method returns the value of the value
attribute multiplied by 2.
To create an object of the MyClass
class, we can use the following code:
my_object = MyClass(10)
This creates a new instance of the MyClass
class with a value
attribute of 10
. We can then call the double_value
method on this object:
result = my_object.double_value() print(result) # Output: 20
This prints out 20
, which is the result of calling the double_value
method on the my_object
instance.
In summary, object orientation is a programming paradigm that emphasizes the use of objects to represent and manipulate data. Python is an object-oriented programming language, and you can define a class using the class
keyword and create an object of that class using the class name followed by parentheses.