0% found this document useful (0 votes)
1 views2 pages

Oops Python

Uploaded by

Adnan Saleem
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Oops Python

Uploaded by

Adnan Saleem
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Object-oriented programming is a programming paradigm that uses objects to represent

and manipulate data. In OOP, an object is an instance of a class, which is a blueprint that
defines the properties and behaviors of the objects.

To create a class in Python, you use the class keyword followed by the class name. For
example:

In this example, MyClass is an empty class.

To create an object from a class, you use the class name followed by parentheses. For
example:

In
this example, my_object is an instance of MyClass.

To define properties of a class, you use the __init__ method, which is called when an
object is created. For example:

In this
example, Person is a class that has two properties: name and age. The __init__ method
takes two arguments ( name and age) and assigns them to the properties of the object
using the self keyword.

To define behaviors of a class, you use methods. Methods are functions that are defined
inside a class and can be called on objects of that class. For example:
In this example, Person is a class that has two properties: name and age, and a method
called say_hello(). The say_hello() method prints a message that includes the name and
age properties of the object.

To call a method on an object, you use the dot notation. For example:

In this example, person is an object of the Person class, created with the name "Alice"
and age 30. The say_hello() method is called on the person object, which prints the
message.

This is just a basic introduction to object-oriented programming in Python. There are


many other concepts and features of OOP, such as inheritance, polymorphism, and
encapsulation, that you can learn as you go deeper into the topic.

You might also like