Hello, nice to see you ready to code. I
In this lesson, we're going to be learning about Objects and Methods in Python.
But let's refresh your memory and review what we covered last lesson, we introduce a Function, which is a block of code, which only runs when it's called; a Parameter is the variable listed inside the parentheses in the Function definition, it's a placeholder for the real values that are sent into the function called Arguments.
As usual, please go to Replit.com and create a new Repl named, you guessed it, PGD_8_Objects.
Objects and Methods are two fundamental concepts in Python. OBJECTS are a collection of data or variables and METHODS are sub programs that update Objects.
Let's explore Objects first. And then Objects are a collection of data that we describe using PROPERTIES. Let's run through a few Properties from the real world. For example:
the Object “human” has the Property “age”,
the Object “fruit” has the Property “color”,
the Object “bicycle” has the Property “size”.
In summary, the Properties an Attribute has can be used to describe the Object. So the Object “human” has the Property “age”, and if I'm 14 years old, the value of “age” is 14. So the values of the Property “age” can change because not everyone in the world is 14.
This wasn't specified at the time we created the Object. Well, that wouldn't really make sense as we want to reuse the code. So if every Object we created had the same value, that would limit us, so we change the value using a Method. A Method is a sub program that acts on data. It's a set of instructions that performs a task.
A Method is referred to by name and can be used or invoked in Python speak at any point in a Python program simply by utilizing the Methods name. important point to remember is that a Method is specific to an Object. That means the Method will only perform the set of instructions on the values in a specific Object called an INSTANCE of the Object. That is because we specified what Methods can be used when we created the Object.
I will continue in our next lesson to explore Objects and Methods and how we create them. See you soon