If a language support object oriented way of programming it means that a large problem can be divided into smaller ones and then we can combine them to get the target output.
It means by using OOP's (Object Oriented Programming) we can achieve the solution of large and complex problems in easier way as compared to procedural programming.
The main features of object oriented programming are
It means by using OOP's (Object Oriented Programming) we can achieve the solution of large and complex problems in easier way as compared to procedural programming.
The main features of object oriented programming are
- Classes and objects
- Polymorphism
- Inheritance
- Encapsulation
- Abstraction
- If we are creating a class, it means that we are actually creating a new datatype.
- We can encapsulate(bind) data members, and functions (methods) into a single unit which is called class.
- Basically class is identified by some name.
- Class represent a blueprint of the object(real world entity).
- int, float, complex, list, tuple, set, dict are all examples of predefined classes in Python.
- Object represent the instant of class.
- By defining a class, we are not actually consuming any memory. Memory will be consume when objects of that class are made, means object consumes memory.
- We can create any number of objects of a single class.
- A simple script is given below for defining and creating object of the class.
class M1:
s=10
def fun1():
print("This is function of class")
print(M1.s) # M1 is class object
M1.fun1()
o1=M1() #We are creating a new object and o1 will referring it
print(o1.s)
o1.fun1() # Error Come here
The output of this script is:
10
This is function of class
10
Traceback (most recent call last):
File "/root/Desktop/p1.py", line 10, in <module>
o1.fun1()
TypeError: fun1() takes 0 positional arguments but 1 was given
Have a look on the above script and try to understand the flow of the program. Don't worry why error is coming, we will understand it later.
s=10
def fun1():
print("This is function of class")
print(M1.s) # M1 is class object
M1.fun1()
o1=M1() #We are creating a new object and o1 will referring it
print(o1.s)
o1.fun1() # Error Come here
The output of this script is:
10
This is function of class
10
Traceback (most recent call last):
File "/root/Desktop/p1.py", line 10, in <module>
o1.fun1()
TypeError: fun1() takes 0 positional arguments but 1 was given
Have a look on the above script and try to understand the flow of the program. Don't worry why error is coming, we will understand it later.
Thanks for your support.
ReplyDeleteI am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai
ReplyDeleteThanks for the feedback.
Delete