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
80% Percent Complete
By Kevin McAleer, 2 Minutes
Python is a rich language with many advanced features. This lesson will introduce you to a few of these features: decorators, generators, and context managers. These tools can help you write more efficient and cleaner code.
Decorators allow us to wrap another function in order to extend the behavior of the wrapped function, without permanently modifying it.
def my_decorator(func): def wrapper(): print("Before function call") func() print("After function call") return wrapper @my_decorator def say_hello(): print("Hello!") say_hello() # prints: Before function call, Hello!, After function call
Generators are a type of iterable, like lists or tuples. Unlike lists, they don’t allow indexing with arbitrary indices, but they can still be iterated through with for loops.
def simple_generator(): yield 1 yield 2 yield 3 for value in simple_generator(): print(value) # prints: 1, 2, 3
Context managers allow you to allocate and release resources precisely when you want to. The most widely used example of context managers is the with statement.
with
with open('file.txt', 'r') as f: file_contents = f.read() # the file is automatically closed outside of the with block
In this lesson, you’ve learned about some of Python’s advanced features: decorators, generators, and context managers. These features can help you write more efficient and cleaner code. Understanding these concepts can be a stepping stone to mastering Python.
< Previous Next >