Mike Driscoll Profile picture
Oct 12 5 tweets 3 min read
One of #Python's many built-in functions is called `id()`. You can use `id()` to return the “identity” of an object.

The id is an integer which is guaranteed to be unique and constant for this object during its lifetime.

#python_builtins_by_driscollis

🧵🐍👇
CPython implementation detail for ids: This is the address of the object in memory.

Identity and equality are NOT the same in Python!

For example, the two lists in the following example equal each other (i.e. have the same contents), but their id is different!
In CPython, there is an optimization where the first 256 integers have the same identity

This can be proven with Python's `id()` function.

So in this case, the identity and the equality are the same
I talk a little bit more about identity versus equality in this short tutorial @mousevspython

blog.pythonlibrary.org/2017/02/28/pyt…
@mousevspython Thanks for checking out my thread on Python's built-in `id()` function.

Follow me for more great tips 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

Oct 11
Today we are going to talk about the basics of unit testing in #Python

🧵🐍👇
The Python programming language includes built-in packages for testing:

🐍 doctest
🐍 unittest
I already did a thread on Python's `doctest`:

Read 13 tweets
Sep 18
Did you know that #Python supports arrays? No, I'm not talking about Python lists. I'm talking about the array module! 🐍🤯

docs.python.org/3/library/arra…

🧵👇
When you create an array object in #Python, the first argument has to be one of the following strings (AKA typecode):

b, B, u, h, H, i, I, l, L, q, Q, f or d

The second argument is optional, but must be a list
Here is an example of using #Python's array module:
Read 4 tweets
Sep 15
One of the harder concepts to learn in #Python are decorators.

So let's take a few moments and learn about them!

🧵🐍👇
It's always good to start with a regular function. Why?

Because you create a decorator using functions!

This function, `doubler()` takes in a number and doubles it. That's it! Image
But wait! #Python functions are also objects. You can get their `__name__` and their docstring (`__doc__`), if they have one.

You can also get a listing of their other methods with `dir()`

What all this means is that you can pass a function to another function! Image
Read 11 tweets
Sep 8
#Python has TONS of great packages and frameworks.

In this thread, I am going to highlight just a few of the THOUSANDS that are available to you on pypi.org

🐍🧵👇
Python has lots of great cross-platform GUI packages:

🐍 PySimpleGUI @PySimpleGUI
🐍 PyQt / PySide
🐍 wxPython
🐍 Tkinter
🐍 @DearPyGui
🐍 EasyGUI
@PySimpleGUI @DearPyGui #Python also has a couple of GUI frameworks for mobile development (i.e. iOS and Android):

🔥 Kivy @kivyframework
🐍 Toga from @PyBeeWare

I have heard PyQt also supports mobile, but haven't been able to verify it
Read 10 tweets
Sep 7
#Python includes more than 200 modules as a part of its standard library.

Today we will look at the `atexit` module

#PythonStdLib 🐍🔥

🧵👇
The `atexit` module in #Python defines functions to register and unregister cleanup functions.

Read more about `atexit` in the docs 📚 here:

docs.python.org/3/library/atex…
The Python docs have several interesting examples of using the `atexit` module.

Here is a module that can initialize a counter from a file when it is imported and save the counter’s updated value automatically when the program terminates
Read 4 tweets
Sep 6
Today is a great day to talk about #Python's package installer, pip!

You can learn all about it in a mini-thread!

🐍🔥🧵
If you need to install a 3rd party #Python package, you will almost certainly need to use pip.

Examples of 3rd party packages include:

🐍 Django
🐍 SQLAlchemy
🐍 requests
🐍 Mypy

with thousands more available on the Python Packaging Index (PyPI) Image
You can install multiple #Python packages with pip as well. 🐍🚀

One way to do that is by separating the package names with spaces when calling pip Image
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

Don't want to be a Premium member but still want to support us?

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!

:(