Object-Oriented Programming with Python in 22 Minutes

Publié le: 16 octobre 2022
sur la chaîne: Zenva
979
30

ACCESS the FULL COURSE here: https://academy.zenva.com/product/pyt...

Learn how to use classes and objects to represent real-world entities in Python!

Object-oriented programming (OOP) structures a program into classes that have a particular set of properties and behaviors. A class is nothing more than a blueprint for creating objects, which lists the fields or attributes (properties) and methods (behaviors) that its instantiated objects will contain. We can use classes to implement advanced concepts such as encapsulation, abstraction, inheritance, and polymorphism.

The whole notion of the OOP is focused on creating reusable and easily-adaptable code. We can think of the fields of a class as simply being variables that store values known only to the object of that class, and in this way, we can always just add or remove attributes from it. Similarly, methods are used to determine the behavior of an object of the class by accessing and altering its fields. Other parts of the code that need access to this information will do so by calling for the object's methods, which are functions that can, in turn, handle such values.

In this short tutorial, we're going to define a GameObject class in Python and set its fields and methods. You'll learn how to initialize the fields of the class by calling on a special method known as initializer (specified by the _init_ keyword). The initializer's only purpose is to set up the object's attributes as soon as the object is created. We'll also cover the specifics of the Python language when it comes to the parameters of the class methods and how to properly format strings.

When working with object-oriented programming languages, such as Python, you'll know exactly where to look when something doesn't go as expected. Instead of having to review your entire code and debug it for hours on end to try and mitigate the problem, you can go looking for the class related to the issue you're having directly and examine it locally instead. That's why knowing how to use classes and objects to better structure your code is a key ability when dealing with large projects or bringing your own projects to the next level!


Sur cette page du site, vous pouvez voir la vidéo en ligne Object-Oriented Programming with Python in 22 Minutes durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Zenva 16 octobre 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 979 fois et il a aimé 30 téléspectateurs. Bon visionnage!