Just don’t make it angry
07 November 2022
I made a robot that can see using sound. #shorts
03 November 2022
Best night of his life
12 October 2022
What happens when robots die?
11 October 2022
Pomodoro robot! This is a work in progress but too cute not to share
30 September 2022
Build your own web server using a Raspberry Pi Pico W using Phew.
28 August 2022
Yukon & Omnibot 3000
Omnibot 3000
Pico W Toothbrush
Whats new in Python 3.13a
Maker Faire Rome 2023
WeatherBot
Data Manipulation with Pandas and Numpy
Computer Vision on Raspberry Pi with CVZone
Learn how to program SMARS with Arduino
Build a SMARS Robot in Fusion 360
Python for beginners
Create Databases with Python and SQLite3
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 >