my experience learning python so far in phase 3
Published: 2024-05-06 22:59:54

Well, phase 3 started off okay and I took a look at everything we were going to do and the basics of Python feeling pretty optimistic. The last 2 phases before this one were pretty engaging and although slightly difficult they were still enjoyable to learn so I assumed this one would be too and for the most part it was, unfortunately, my grandmother got very sick and I had to take care of her so I ended up falling behind a lot and even when I did have the time I found it difficult to work up the motivation to actually get started and make progress on my overdue assignments.

As the deadline got closer and closer and I felt like my back was up against the wall what ended up motivating me to actually get my work done instead of just staring at it for hours was the fear of failing this class and having all of that money wasted or having my grandfather disappointed that I failed a phase so after weeks I finally got to work and got almost completely caught up with all of my assignments so after this blog post I only have the final project which admittedly does seem difficult, but I think I'll manage somehow now that I'm finally focused on my work and am not getting distracted easily.

That being said, I think the subject I'll talk about in this post is object-oriented programming that we went over this phase. OOP(Object-Oriented programming) is a wonderful way of organizing your code into neat little packages called objects. It's similar to organizing a closet, you group similar stuff together to make it easier to find.

the first thing to go over in OOP is

1. **Classes and Objects**

- Classes are like templates for creating objects or like an architects plans, they tell Python how to make stuff

- Objects are instances of classes, they're like the actual things you make using those templates.

```
class Car:
    def __init__(self, make, model):
        self.make = make
        self.model = model

    def display_info(self):
        print(f"Car: {self.make} {self.model}")
```

2 **Encapsulation**

- Encapsulation just means to keep everything together, related things get put in the same place so its easier to manage

- its like putting all of your car parts in one box instead of scattering them all over your garage

3 **Inheritance**

- Inheritance is like passing down traits from your parents, you get some stuff from them but you can also add your own twist.

- so if for example you have a class for regular cars, you can make a new class for electric cars that inherits some stuff from the regular cars class.

```
class ElectricCar(Car):
    def __init__(self, make, model, battery_capacity):
        super().__init__(make, model)
        self.battery_capacity = battery_capacity

    def display_info(self):
        super().display_info()
        print(f"Battery Capacity: {self.battery_capacity} kWh")
```

4 **Polymorphism**

- Polymorphism is like being able to use the same tool for different jobs, you don't need a separate screwdriver for every type of screw.

- So, whether you're dealing with a regular car or an electric car, you can use the same display_info method without any issues

So that's the basic rundown on objects in Python, it's not the most exciting thing in the world but it is extremely helpful for keeping your code organized, using OOP can help make your code much more manageable