OOP in Python | Object Oriented Programming | Python for Beginners #lec84
Summary
TLDRThis video introduces the concept of Object-Oriented Programming (OOP) in Python, explaining why it is necessary over the traditional procedure-oriented programming approach. The speaker highlights the limitations of using global variables and functions in large projects and the need for data security, which OOP provides. The video explains the basic concepts of OOP, such as classes and objects, using relatable examples. Additionally, the speaker touches on the difference between attributes and methods, providing an overview of the benefits of using OOP for managing complex projects. Future videos will explore OOP concepts in greater depth.
Takeaways
- 📚 The video introduces the concept of object-oriented programming (OOP) in Python.
- 🔍 The purpose of the video is to explain why OOP is necessary after using procedure-oriented programming (POP).
- ☕ The previous project (coffee machine project) used POP, and now the focus shifts to OOP.
- ❗ In POP, data security is a concern as global variables are freely accessible by multiple functions, making it hard to manage large-scale projects.
- 🔐 OOP addresses data security by focusing on objects and encapsulating data, preventing unauthorized access.
- 🏗️ OOP helps in managing complex relationships in large projects by modeling real-world objects and their interactions.
- 👨🏫 The video uses the example of a YouTube channel, where different roles like instructor, editor, and social media marketer represent objects in OOP.
- 💡 A class is a blueprint for creating objects, and objects are instances of classes in OOP.
- 🔄 OOP supports concepts like inheritance, polymorphism, and data hiding, which are absent in POP.
- 📝 The video promises future discussions on topics like inheritance, polymorphism, abstraction, and more details about OOP with programming examples.
Q & A
What is the main focus of this video?
-The main focus of this video is to explain why we need Object-Oriented Programming (OOP) in Python, especially after using the procedural programming approach in earlier projects.
Why is Object-Oriented Programming (OOP) introduced after using procedural programming?
-OOP is introduced because procedural programming (POP) is not efficient for handling larger, more complex projects. POP lacks features like data security, inheritance, and modularity, making it difficult to manage large codebases with many functions and global variables.
What is the key difference between procedural programming and object-oriented programming?
-The key difference is that procedural programming focuses on procedures or functions, while object-oriented programming focuses on objects that combine data and functionality, providing better data security and modularity.
What is one major drawback of procedural programming mentioned in the video?
-One major drawback is the lack of data security. In procedural programming, global data can be accessed and modified by any function, which can lead to unexpected behavior and errors in larger projects.
Why is data security important in programming?
-Data security is important because, in real-world projects, not all data should be accessible by all functions or users. For example, some personal information should be kept private and only accessible by authorized entities.
What are some features of OOP that procedural programming lacks?
-OOP includes features like inheritance, polymorphism, data hiding, and encapsulation, which procedural programming lacks. These features help manage large projects by making code more modular, reusable, and secure.
What is the role of classes and objects in OOP?
-In OOP, a class is a blueprint or template for creating objects, while objects are instances of that class. Objects have attributes (data) and methods (functions) associated with them, encapsulating both data and functionality.
Why is everything considered an object in Python?
-Everything in Python is considered an object because Python uses classes to define data types. Variables, strings, functions, and even integers are instances of predefined classes in Python.
What is meant by the term 'attributes' in OOP?
-In OOP, 'attributes' refer to the data or properties associated with an object. These are the variables defined within a class that hold information about the object.
How does OOP help in managing complex real-world projects?
-OOP helps manage complex projects by encapsulating data and functionality within objects, providing better modularity, data security, and scalability. It also allows for easier maintenance and debugging by organizing code around objects and their interactions.
What is a simple analogy used in the video to explain OOP concepts?
-The video uses the analogy of running a YouTube channel. Initially, a single person manages everything, but as the channel grows, specialists (instructors, editors, marketers) are hired for specific tasks. Similarly, in OOP, different objects (instructors, editors) handle different tasks, making the project more manageable.
Outlines
🚀 Introduction to Object-Oriented Programming (OOP)
In this paragraph, the presenter introduces the concept of object-oriented programming (OOP) in Python, emphasizing its importance in programming. They reference a previous video that discussed a coffee machine project and explain that future videos will cover OOP concepts such as classes, objects, inheritance, and polymorphism. The purpose of this video is to explain why OOP is necessary and how it differs from previous approaches.
🔍 Limitations of Procedure-Oriented Programming (POP)
The presenter explains the drawbacks of procedure-oriented programming (POP), where functions and global variables are interconnected. While this approach works for small projects, it becomes unmanageable with larger projects due to the complexity of managing global variables and tracking their usage across functions. The primary issue with POP is the lack of data security, as global data can be accessed and modified by any function, leading to potential errors.
📊 Data Security and Real-World Project Challenges
This paragraph highlights the importance of data security in large-scale projects and real-world applications. The presenter explains that POP lacks the necessary structure to protect and manage data, making it difficult to handle complex projects. They stress that OOP addresses this issue by focusing on data security and controlling how data is accessed and modified. OOP also solves other limitations of POP, such as the lack of inheritance, polymorphism, and data hiding.
🧠 Understanding Objects in Python
Here, the presenter shifts focus to explaining what objects are in Python. They give examples of variables, strings, and functions, showing how everything in Python is treated as an object. The presenter demonstrates this by running code snippets that reveal variables are instances of predefined classes, like 'int' or 'str', and functions are objects of the 'function' class. This sets the foundation for understanding the object-oriented nature of Python.
🛠 Introduction to Classes and Methods
The concept of classes and objects is introduced. The presenter explains that classes are blueprints for creating objects, while objects represent real-world entities. They give an example of modeling a YouTube channel with different roles, such as instructor, editor, and social media marketer. Each of these roles is an object with attributes (data) and methods (functions), and the presenter emphasizes how OOP allows for better organization and scalability by modeling real-world scenarios.
🏗 Simplifying Real-World Problem Modeling with OOP
The presenter explains how OOP helps simplify the management of real-world problems by breaking down complex tasks into smaller, manageable objects. They provide a YouTube channel example, where different roles like instructor and editor are modeled as objects, each with specific tasks. This organization allows for better control and scalability of projects. The presenter also introduces the concept of class as a blueprint for creating multiple objects and explains how attributes and methods are associated with objects.
🎯 Conclusion: Why We Need OOP
In this final paragraph, the presenter summarizes the advantages of OOP and its importance in managing real-world projects. They briefly explain the differences between classes and objects and how OOP provides a structured way to handle complex relationships and data security. They promise that future videos will dive deeper into the syntax and creation of classes and objects in Python, emphasizing the relevance of OOP in industry and large-scale projects.
Mindmap
Keywords
💡Object-Oriented Programming (OOP)
💡Procedure-Oriented Programming (POP)
💡Global Variables
💡Data Security
💡Class
💡Object
💡Attributes
💡Methods
💡Data Hiding
💡Inheritance
Highlights
Introduction to object-oriented programming (OOP) and its importance in Python programming.
Explanation of why OOP is needed: It provides better handling of large-scale projects compared to procedure-oriented programming (POP).
POP focuses on procedures and functions, while OOP focuses on objects and data security.
In POP, global variables and data can be accessed and modified by multiple functions, which can lead to errors and security issues.
OOP helps model real-world problems by organizing code into objects, making it easier to manage complex projects.
Data security is a key advantage of OOP. In OOP, data is encapsulated within objects, ensuring controlled access.
Introduction to key OOP concepts like classes, objects, inheritance, polymorphism, and data abstraction, which will be discussed in future videos.
Real-world analogy: A YouTube channel where multiple tasks (editing, teaching, social media) can be managed efficiently using OOP principles.
Explanation of attributes (variables) and methods (functions) in OOP and how they are tied to objects rather than free-floating in code.
Objects are instances of classes, and classes act as blueprints for creating multiple objects.
OOP allows for scalability and simplifies relationships between different parts of a large project.
Introduction to the built-in classes and objects in Python, such as `int`, `str`, and `function`, showcasing how everything in Python is an object.
Practical example: How to model an instructor, editor, and other roles in a project using OOP principles.
Explanation of how object-oriented programming mirrors real-world concepts, like creating virtual entities with specific roles and functions.
Encapsulation in OOP allows control over how data is accessed and modified, ensuring data security and proper management.
Transcripts
hey everyone I hope you are safe and
doing good so in the series of learning
path and programming language in the
previous video we have seen one project
that was a coffee machine project I hope
you got that thing and you have done
that right now from this video onwards
we are going to start a very important
Concept in Python that is object
oriented programming
right
so we will be discussing everything
about object oriented programming all
the concepts and all in further videos
but this video is about what this video
is basically about why we need
object-oriented programming till now
also we have done few projects and we
have written many programs without the
need of object oriented programming yes
then why now why we need oop
right until now we were we were
following which approach
right so basically in this video I'll
try to answer this question why do you
need object learning programming and
then further we'll discuss what is an
object and then
what is object on your programming
right
and later videos we'll be discussing all
the concept classes objects and
inheritance polymer facial obstruction
everything about oop right
so now before that I just want to tell
you something it is important specially
for those who are preparing for gate and
ESC for gate and escs parents right it's
like a never before opportunity for you
guys an academy is back with combat yes
and this time it is ultra combat
so now you have a chance to get up to 90
scholarship and many rewards such as
MacBook Dell laptops Samsung phones and
many more
would be conducted on 23rd of July and
the time is 11 am how many question you
will get 40 question mcqs would be there
in this test and the time limit is 120
Minutes you will get to solve the
questions now what are the syllabus
syllabus will be General aptitude
engineering mathematics and Technical
and the most important thing is you can
enroll for this test for this combat for
free you don't need to pay anything no
registration fee nothing right so do not
miss this opportunity and enroll today
the link I'll put in the description box
of this video and you can use my code
jkl10 to enroll for free in this combat
right so all the relevant information
and Link you will get in the description
box of this video you can go and check
out okay
now let's try to find out the answer of
this question why basically we need OB
first see in the previous video we have
done this project the coffee machine
project so this was our project the menu
resources profit uh is a variable that
is global resources also dictionary
having information that is global and we
have defined many functions right and
these functions are calling like
here we are calling these functions and
these are returning something and they
are interlinked right see in this
function we are in make coffee in this
function we are updating the resource
item resource item means these item
because these are Global right and this
function also we are accessing the
resources because we are just comparing
here we are not updating anything
and in this like we are we are we are
updating this profit This Global
variable profit we are updating this
right so these functions are interlinked
with each other having
many relationship
right
okay now this approach is what here we
are following the processor oriented
programming this approach pop approach
right processor means these functions
are known as procedure means procedure
basically means the steps how we are
going to perform some tasks right and
how we are going to perform this
function the check resources these are
obviously the statements or the tasks we
are writing the steps we are writing
so these are what procedures so we can
say function so this is what pop
approach
right now yeah that is fine we are
following pop approach so why now we
need oop approach because this is also
fine right but in pop approach we can
handle only small project
because see it is just a simple one
coffee machine project and here see
we are having multiple functions and the
main important thing is these functions
are updating Global variables the profit
is global variable a resources this
dictionary is also Global obviously
so in many functions
more than one function we are accessing
this resource and one function is
updating this resources and in one
function we are updating this profit
right so we are updating the global
variable or the data
so suppose we are dealing with a large
project a large scale project there we
are having multiple functions 50
functions or 100 functions and many
Global variables right so it would be
very difficult for you guys to track
like which function is accessing which
global variable which function is you
know updating which global variable and
accidentally if we update a global
variable global data in any function
then maybe it will give us some error or
some unusual you know result right some
unexpected output
right so main thing is
I think now you have noticed main thing
we are focusing in
in this approach pop approach on
functions
how to do the task the functions the
procedures
not on data data is now data here is
freely moving
during the whole program because
obviously the global data is moving
freely any function can access this data
any function can update this data right
it means there is no data security data
is freely moving we are just focusing on
the procedures of the functional means
you can say how to do the task
on this we are focusing more
so one drawback of this is what data
security I hope you got it why I am
saying that it there is no data security
in pop approach I hope you got this
thing now right with the help of this
example so now if you want to handle any
real world problem any large project
right then definitely it would be not
easy
to manage that project to implement that
project with the help of this pop
approach right because of the complexity
and the relationship between those
functions and all how to manage the
relationship how to check which function
is how to track which function is using
which global data and which function is
updating which data and all right
because we are not focusing on data more
and if suppose if maybe you think like
we can do we will take like no global
data is there we just change this type
of this global data just take local data
so all the functions which are accessing
that global data you have to do
accordingly the changes in those
functions as well you have to resolve
those functions as well right because
maybe many functions are using that
global data right
so because of the complexity and the
number of relationship are very complex
here it would be very difficult to
manage that thing with the help of this
pop approach right and obviously the
data security is not there and yeah
obviously if you are implementing any
real world project then we know that the
data is how much the data is important
like maybe I want like anybody can
access my name jayanti but only few
person can access my mobile number
not all the person obviously I want my
data safe
so if you want to implement if you want
to model any real world problem real
world project then definitely you have
to focus on data security
and data security is not in pop you
cannot
you like you cannot Implement data
security you cannot achieve data
security in pop approach that is why we
need another approach and that is in oop
yes we are having data security and why
that I'll tell you how you can Implement
data security in object-oriented
programming and there are other
drawbacks also in this approach pop
approach like there is no inheritance no
virtual function no operator overloading
no polymorphism no data hiding many
other things are there but now I know
you don't know about what is inheritance
what is data hiding what is virtual
function what is polymorphism so that is
why it will not be you know it would not
be easy for you to understand these
things right but I'm sure data security
is one thing one drawback that you got
exactly what is data security and why I
am saying this right same thing in later
videos we will discuss what is
inheritance what is like you can say
that virtual function and all will be
discussing polymorphism data obstruction
data hiding then you will get why I am
saying right now like pop is not having
these things right it's okay if you're
not getting anything of these terms it's
okay
it's normal right because its first
lecture of oop and definitely it would
not be easy for you to understand
everything in one video right
but till now I hope the data security
you got right now
object-oriented programming is used to
model now the real world projects right
now first thing
we'll see like what is object
we know python is object-oriented
programming and I think you have heard
this line also everything is considered
as an object in Python right why I am
saying this let's see with the help of
this example
see if I take a variable like a is equal
to 1 and if you print the type of uh
this variable a
then what you will get just focus on the
answer see
class
int
class
because here we are having a class that
is predefined in the library of python
class is int and this a is what it's
just an object of this class int
if I'll not take this a if I
like
want to find out the
type of this string hello now let's run
this C Class Str
now this hello is an object of class
Str so this is built in class in Python
that is why I am saying everything you
deal now this hello is what an object
they say is also an object everything
you deal is in Python is what
an object let's take if I have a
function
display
and there I am just using the pass
statement nothing I'm going to write and
then I want to find out
this type of this
display function
this you need to write down name of this
function display let's run this
and see class
function so there is a class in build
class function and this function is an
just an object of this class this class
that is why I was I was saying like
everything in Python whether it's
variable function or any string or not
everything is considered as object
now you got
why we are saying like what is an object
and why we are saying this so you got
this idea in built classes we are having
python many inbuilt classes right and
the object you can use
fine and see there is a class Str see
you know this hello is what
just it's a string if you want to find
out type so the class will be string so
if I use something like hello don't
so the class Str that is having many
functions lower title index and many
function see
right so these functions you can use on
this object because this object is of
Str class type right so if I use this
function only lower
and if I print if I run this C
this is already in lower so it would be
let's suppose
I'll do this in capital letter and C it
will print
in small letter capital letter but don't
lower means small letter so there are
many inbuilt function also that you can
call on that object with the help of dot
operator right whatever the object dot
whatever the function is there of that
class so many classes and those classes
are having inbuilt functions those you
can use on those object right
so I guess you have some idea now
objects and all
right
now uh oriented oriented means in simple
English language if we say then like
it's interested in a particular thing or
a particular person so we are basically
interested in object that is why it is
known as object oriented programming so
are interested or main focus is in on
objects
right that is why it is known as oop
like you know this shop is male oriented
or female oriented means in this show of
the product all the product you will get
are of males not females male oriented
female oriented like this so object
oriented you focus on we are interested
in objects
that is why it is known as
object-oriented programming right
so I hope the answer of why why we need
oop that is somewhat clear to you guys
because we have done some advantage of
oop not all
because everything will be discussing
later videos then you will get all the
advantages and benefits of Pop if you
you know understand to a certain level
what is op and what are the advantages
then definitely you will get why it is
always better to use op and why in the
industry uh you know in the companies
they use this op approach to you know
Implement project large project real
world project
right now let's take a simple example if
a real world problem I'm taking if I am
going to start a YouTube channel right
so in starting I'm the only one like one
man army so I can teach some subjects
I am the editor I am thumbnail designer
I am the social media marketer I am the
instructor right
but I want to start many courses C C
plus plus Java computer network dbms
operating system data structure web
development course and many more courses
then definitely if I am a one-man Army
then it would be very difficult for me
to manage everything
right
so this would become more complex if you
want to grow your YouTube channel
obviously
you got it right for one person
fine now what I can do
to solve my problem I can hire like if
I'm going to start uh another course and
that is web development
so I can hire one instructor
that will teach this course
right
and maybe one editor
that will do the editing as well as
thumbnail thumbnail designing one I will
hire social media marketer
and I would be like manager
right now my task is to manage these
things now this manager
like suppose the manager is me
so I don't need to go in so much detail
of how they are going to do their task I
don't need to tell how to teach to the
instructor how do you need to tell how
to edit the videos how to design
thumbnail
to an editor I don't need to tell
a social media marketer how to do your
job
right
I don't need to worry about these things
because these are expert in their job
they know how to do their job better
than me
I guess
right
so this is going to simplify my task and
simplify the relationship
so the same approach or the same concept
we can use to simplify our code
to implement larger project to make a
project more scalable the same approach
right
and see now one more thing if I want to
like start one more course about Java
so or before that let me just tell you
something now
let's take one thing like I'm taking
this instructor so this instructor is
having
and see as we know object-oriented
programming oop is used to model real
world project right
so let's create now a virtual YouTube
channel so let's create a virtual
instructor virtual editor virtual social
media marketer and everything virtually
let's create right now
we need to model this these things in
structure editor and all in programming
right we need to model this thing in
programming and obviously using oop
approach we use we model right now this
instructor this is Hamming
some information right and it will do
some task
right
so two thing what he or she has or what
he or she does so it is Hamming
obviously some information like name of
the instructor maybe address phone
number and like some attribute like has
books
then we can say like true having books
has camera
because to record
the lecture we need camera and like has
laptop
that is also true or maybe something is
false so it is having something some
information right and it will do
something what it will do teach
so we can say like deaf teach we can
define a function and here you can write
down some statements
and maybe other thing other function we
can do like depth it will also prepare
quiz
so that is other thing
so
this is what it is having this is what
it will do
right
now in programming terms see these are
simply we know these are variables
if simply I say because these are
variables obviously and these are
functions but in case of object oriented
programming we call the variables as
attributes
and these are known as methods not
functions methods
and there is some reason because see
these variables and these functions are
not free floating in pop the variables
we take like global data that was free
floating move anywhere
these variables these functions are
associated with
and entity that is instructor
so these things are associated with this
thing
right that is why these are known as not
simple variables attributes not simple
functions methods
right because they are these are
associated with something these are not
free floating in your programs right
so in op we try to model real world
object so and these objects are having
something some information these objects
do something so what they have
that thing is modeled with the help of
attributes and what they do that thing
is model with the help of methods right
so simply we can say an object is just a
way of combining some piece of data and
some functionality into a same thing
into same thing like into a box this is
same thing in a box only we are having
this and this as well right
now
if I want to start another course like
Java
so I can hire one more instructor if I
want to start another course I can hire
one more instructor that is fine right
so instructor suppose I have higher like
Gia
one more instructor payal
maybe one more instructor so now see now
these actual thing these actual person
these are known as objects
in object-oriented programming these are
objects right and this this instructor
this is simply a blueprint or a design
this is known as class
so class is simply a blueprint just to
create objects so these actual things
these are objects right like if you are
going to build a house then the map or
the sketch
of that house is what a blueprint a
design you have and using that design
you can build a house so that house is
object and that sketch or that map is
what a class and see using that single
map we can we can construct we can
design multiple houses right
so we have only one class we have only
one design we have only one blueprint
using that we can build many we can
create we can generate many objects
right so I hope you now you got the
basic idea or an overview what is a
class what is an object right and why
basically we need object oriented
programming right
so now the overview of object-oriented
programming like basically why we need
this right and what is object-oriented
programming what is simply an audio of
class and object and this thing is clear
to you guys right now in the next video
we will see in more detail what is the
class what is an object how to create a
class how to create an object the syntax
and everything right with the help of
program right so now it's in the next
two till then bye like it
Weitere ähnliche Videos ansehen
Classes and Objects in Python | OOP in Python | Python for Beginners #lec85
Object-oriented Programming in 7 minutes | Mosh
Introduction to OOPs in Python | Python Tutorial - Day #56
Excel VBA Programming - The Excel Object Model | 1 - Object Oriented Programming in Real Life
OOPS Interview Questions and Answers | Object Oriented Programming Interview Questions C#
Features of Object Oriented Programming Part 2 | C ++ Tutorial | Mr. Kishore
5.0 / 5 (0 votes)