Starting in Python 3.7, the `breakpoint()` built-in function was added

It is defined in PEP 553 and simplifies adding a breakpoint to your code

#python_builtins_by_driscollis

๐Ÿงต๐Ÿ๐Ÿ‘‡
You can read about the `breakpoint()` function for Python here:

python.org/dev/peps/pep-0โ€ฆ
Here is some sample code showing how to use the `breakpoint()` function in your Python code Image
Here is a GIF that shows how to run the code. When a breakpoint is reached, the Python debugger (pdb) will launch automatically
If you'd like to learn more about debugging your #Python code with `breakpoint()` and the `pdb` module, you should check out my tutorial @mousevspython

blog.pythonlibrary.org/2020/07/07/pytโ€ฆ
@mousevspython I hope you enjoyed learning about Python's `breakpoint()` function. It's super handy!

Follow me to learn more about the Python programming language!

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Mike Driscoll

Mike Driscoll Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @driscollis

9 Jan
Let's talk a little about accessing #Python dictionaries!

Most beginners will access a dictionary like this:

๐Ÿงต๐Ÿ๐Ÿ‘‡ Image
What happens if you try to access a key that doesn't exist in a #Python dictionary?

You'll get a KeyError! Image
There are several different ways to handle a KeyError. ๐Ÿโš ๏ธ

You could wrap it in a `try/except`. Another approach is to use the `get()` dictionary method, like this: Image
Read 6 tweets
7 Jan
Python includes a built-in callable named `bytearray()`.

The bytearray class is a mutable sequence of integers in the range 0 <= x < 256. They return a new array of bytes

#python_builtins_by_driscollis

๐Ÿงต๐Ÿ๐Ÿ‘‡
A bytearray in #Python takes the following optional arguments:

๐Ÿ source[optional]: Initializes the array of bytes
๐Ÿ encoding[optional]: Encoding of the string
๐Ÿ errors[optional]: Takes action when encoding fails
It is often useful to see an unfamiliar concept in action. Here are two examples of creating a bytearray using different encodings and printing them out Image
Read 5 tweets
4 Jan
Starting in Python 3.6, you can create asynchronous comprehensions!

Come learn about them with me in this thread!

๐Ÿงต๐Ÿ๐Ÿ‘‡ #python_builtins_by_driscollis
Asynchronous comprehensions were defined in PEP 530.

You can check out the nitty gritty details here:

python.org/dev/peps/pep-0โ€ฆ
When you go look at that example, one of the first examples you will see looks like this the following

If you attempt to follow that syntax though, you'll end up with SyntaxError ๐Ÿโš ๏ธ
Read 5 tweets
30 Dec 21
There are several ways to remove items from a #Python list.

Let's learn about how to remove items with Python's `del` keyword first!

Here you are deleting the 2nd item from the list. Remember, lists are 0-indexed!

๐Ÿงต๐Ÿ๐Ÿ‘‡
What happens if you attempt to delete an item at an index that doesn't exist?

Python will raise an IndexError!
You can also delete ALL the items in a #Python list by using the following syntax:
Read 4 tweets
29 Dec 21
The primary method for adding items to a #Python list is by using its `append()` method.

The `append()` method is useful for adding one item at a time!

๐Ÿงต๐Ÿ๐Ÿ”ฅ
One #Python list gotcha to watch out for it appending a list to another list.

It may not work the way you want it to!

In this case, it adds the entire list as an element in your original list. In other words, you now have a nested list!
If you want to add the items in a Python list to another list, you should use the `extend()` method
Read 5 tweets
16 Dec 21
Today I want to talk about generators in #Python!

๐Ÿงต๐Ÿ๐Ÿ‘‡
Python functions will always return one value

Python generators can return one OR more values!

A generator works by "saving" where it last left off (or yielding) and giving the calling function a value.

A generator function requires Python's yield statement
To create a generator in #Python, you must use the `yield` keyword.

Here's an example that can generate an infinite number of return values:
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(