Diana Gastrin

Python: Behind the Scenes

Python secretly caches integers from -5 to 256. This is just one of the internal optimizations that explains its most surprising behaviors.

Python: Behind the Scenes
#1about 5 minutes

Understanding the core attributes of Python objects

Every object in Python is defined by its value, ID, and type, with mutable objects like lists differing from immutable ones like tuples.

#2about 2 minutes

Exploring Python's dynamic and duck typing model

Python uses dynamic typing, where a variable is a pointer to an object, allowing for flexible 'duck typing' based on method availability rather than inheritance.

#3about 6 minutes

Navigating variable scopes with global and nonlocal

Python resolves variables using the LEGB rule (Local, Enclosing, Global, Built-in), and the `global` and `nonlocal` keywords are used to modify variables in outer scopes.

#4about 2 minutes

How Python simulates private methods using name mangling

Python doesn't have true private methods, but it uses name mangling on methods prefixed with a double underscore to discourage direct access from outside the class.

#5about 3 minutes

Understanding boolean logic and short-circuit evaluation

The `and` and `or` operators use short-circuit evaluation, stopping as soon as the outcome is known and returning the actual object that determined the result.

#6about 5 minutes

Exploring comparison operators and Python's caching behavior

The `is` operator checks for object identity, revealing Python's internal caching of small integers and simple strings for performance optimization.

#7about 1 minute

Audience Q&A on slots, globals, and private properties

The speaker answers audience questions regarding the relevance of `__slots__` in modern Python and the best practices for using `global` and `nonlocal` keywords.

Related jobs
Jobs that call for the skills explored in this talk.
SabIna compys

SabIna compys
Vienna, Austria

Remote
20-100K
Intermediate
JavaScript
.NET
+1

Featured Partners

Related Articles

View all articles
CH
Chris Heilmann
All the videos of Halfstack London 2024!
Last month was Halfstack London, a conference about the web, JavaScript and half a dozen other things. We were there to deliver a talk, but also to record all the sessions and we're happy to share them with you. It took a bit as we had to wait for th...
All the videos of Halfstack London 2024!
AV
Admir Video
gif
gif
DC
Daniel Cranney
Why developer experience matters
With technology embedded in almost every aspect of life, and with developers building and maintaining these tools, it’s ensuring that developers operate in the digital world with speed and efficiency, if we are to see these same benefits in the offli...
Why developer experience matters
SD
Sabina Dapo
New Test
The basic purpose of narrative is to entertain, to gain and hold readers’ interest. However narratives can also be written to teach or inform, to change attitudes / social opinions e.g. soap operas and television dramas that are used to raise topical...
New Test

From learning to earning

Jobs that call for the skills explored in this talk.

Python Engineer

Usersnap
Vienna, Austria

Intermediate
Python
Amazon Web Services (AWS)