Build Your Own AI Assistant Part 1 - Creating the Assistant
116820 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
114678 Views
Control Arduino with Python using Firmata / PyFirmata
87081 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
57314 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
53588 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
52067 Views
SMARS Lab upgrade with PyCharm
Chicken Nugget Piano
Pi Tray - Mini-rack - Part II
Weather Station Display
Pi 10 Inch Mini-rack
Installing and Using DeepSeek-R1:1.5 on a Raspberry Pi with Docker
Mini-Rack 3D Design Tutorial
0h 20m
Using the Raspberry Pi Pico's Built-in Temperature Sensor
0h 24m
Getting Started with SQL
0h 32m
Introduction to the Linux Command Line on Raspberry Pi OS
0h 42m
How to install MicroPython
0h 8m
Wall Drawing Robot Tutorial
0h 22m
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
40% Percent Complete
By Kevin McAleer, 2 Minutes
In this lesson, we will explore the principles of object-oriented programming (OOP) in Python. Python is an object-oriented language, and OOP concepts provide a clear structure for writing code which makes it easier to create complex applications.
object-oriented programming
classes
objects
class
object
methods
inheritance
In Python, almost everything is an object, with its properties and methods. A Class is like an object constructor, or a blueprint for creating objects.
properties
# Define a class class Car: def __init__(self, color, brand): self.color = color self.brand = brand # Create an object my_car = Car('red', 'Toyota') print(my_car.color) # Prints 'red' print(my_car.brand) # Prints 'Toyota'
Methods are functions defined inside the body of a class. They are used to perform operations with the attributes of our objects.
Methods
class Car: def __init__(self, color, brand): self.color = color self.brand = brand # Define a method def honk(self): return "Beep beep!" my_car = Car('red', 'Toyota') print(my_car.honk()) # Prints 'Beep beep!'
Inheritance is a powerful feature in object-oriented programming. It refers to defining a new class with little or no modification to an existing class. The new class is called derived (or child) class and the one from which it inherits is called the base (or parent) class.
Inheritance
derived
base
class Vehicle: def __init__(self, color): self.color = color def honk(self): return "Honk honk!" # Car class inherits from Vehicle class Car(Vehicle): def __init__(self, color, brand): super().__init__(color) self.brand = brand my_car = Car('red', 'Toyota') print(my_car.honk()) # Prints 'Honk honk!'
In this lesson, you’ve learned about object-oriented programming in Python. We’ve covered the basic principles of OOP, including classes, objects, methods, and inheritance. These concepts provide a clear structure for writing code and make it easier to develop complex Python applications.
< Previous Next >