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
An alternative to using `extend` is to "add" two lists together using the addition symbol: +

Here's how:
I hope you enjoyed learning about appending, extending and adding lists together!

Follow me for more great information on Python!

โ€ข โ€ข โ€ข

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

30 Dec
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!

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

Python will raise an IndexError! Image
You can also delete ALL the items in a #Python list by using the following syntax: Image
Read 4 tweets
16 Dec
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
14 Dec
Iterators in #Python are usually defined as needing the following two methods:

๐Ÿ __iter__ - provides iteration support
๐Ÿ __next__ - returns the next item in the container

๐Ÿงต๐Ÿ๐Ÿ‘‡
A #Python list isn't considered an iterator. It is an iterable, something that you iterate over. But because lists don't define `__next__`, they aren't technically an iterator.

However, you can turn a list into an iterator using the built-in `iter()` function: Image
You can create your own iterators in #Python by adding the appropriate magic methods to your class.

Here is an example: Image
Read 5 tweets
4 Dec
A lot of people use #Python for automation. Let's talk about some of the packages you can use this task!

๐Ÿงต๐Ÿ๐Ÿ‘‡
PyAutoGUI is useful if you need to control the mouse and keyboard on your PC with Python

You can use PyAutoGUI to fill out forms, take screenshots and much more

pyautogui.readthedocs.io/en/latest/
Pywinauto is also for controlling the mouse and keyboard, but is specifically targeted at Windows

pywinauto.readthedocs.io/en/latest/
Read 8 tweets
3 Dec
I wrote a book about creating GUIs with #Python a couple of years ago.

In it, I created a SQLite database viewer application with #wxPython in under 100 lines of code

๐Ÿงต๐Ÿ๐Ÿ‘‡
Here is the SQLite database viewer I created with #Python and #wxPython for the book

Note: This code should work fine on Windows, Mac and Linux
You can get the code for my SQLite database viewer on GitHub here:

github.com/driscollis/appโ€ฆ
Read 5 tweets
3 Dec
Let's talk about type hinting in #Python

๐Ÿงต๐Ÿ๐Ÿ‘‡
Type hinting is not enforced by Python. You can enforce it with outside packages, such as Mypy or with your Python IDE
Type hinting is most useful when you have a large team you are working with or with a large codebase.

Type hinting is also useful for introspection when creating Python packages
Read 6 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!

:(