Python 3, an Illustrated Tour Transcripts
Chapter: Numbers
Lecture: Long Unification

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In this video we're going to talk about pep 237, came out in Python 3 and this is the unification of long and integer types.
0:08 From the pep it says there is also the greater desire to hide unnecessary details from the Python user when they're irrelevant for most applications.
0:16 It makes sense to extend this convenience to numbers. If you're familiar, in Python 2 there was a long integer type and a normal integer type.
0:26 And you could tell one from the other because when you print it out a long type there was an L after it.
0:31 Now Python supports arbitrary precision in integers it's only limited by the amount of memory you have
0:36 so you can make pretty big integers if you want to. Here's an example of creating big integers and we're calling the sys.getsizeof on our integers
0:45 and just seeing that as we create bigger and bigger integers, that the number of bytes required to store those integers gets bigger.
0:53 And so what's happening here is that Python's doing an automatic transition from the native integers to these longer integers,
1:02 but it's hiding that from you, you don't notice it. Typically we don't even inspect a number of bytes that we're using in Python,
1:09 but this just allows us to see that we can make arbitrary large integers and they'll just use more memory, but Python will allow us to do that.
1:18 If you're interested in the details of this you can look at the c code on or in the GitHub project
1:23 and that's in the include/longintrepr.h and objects/longobject.c the details of how this is handled.
1:33 For most people this isn't a big deal because again in Python, we just let Python do what it wants to do.
1:39 and if we have an error we deal with the error, but typically, when we're dealing with integers or whatnot there aren't errors
1:45 with this and the float division that we saw prior a lot of the inconsistencies or warts in Python are hidden away from end users.

Talk Python's Mastodon Michael Kennedy's Mastodon