PyCon UK 2019

More Than You Ever Wanted To Know About Python Functions
2019-09-13 , Assembly Room

Let's talk about functions, methods, callables and closures - what they are, what you can do with them ... and what's inside.

Afterwards you'll know more about callables, along with techniques both practical and so extreme your colleagues will never let you merge them to master.


What exactly are functions? Let's talk about functions, methods, callables and closures - what they are, what you can give them, what they can give you, what you can do with them ... and what's inside.

You probably think you already know everything about functions, but you probably don't!

Input & Output: How do you get things in and out of functions? I'll cover parameters and the myriad of ways they can be specified, provided and accessed - including helpful hints to avoid common mistakes! I'll cover return values, briefly, along with variable scopes and exceptions.

Closures: What are they, how do they work and how they can affect memory usage.

Methods: How does a method differ from a function, when are they made, how do they work (where does self come from?) and how to access the function inside every method.

__magic__:Make your own callables from any object!

Introspection: Using modern Python techniques, what can you find out about a function, and what can you do with that information?

Bytecode: What happens if you open up a function and look at its insides? Can you change it and put it back together again? (Spoiler: Yes, you can.)

By the end of this talk, I guarantee* you'll know more about callables than when you walked in, along with techniques both practical and so extreme your colleagues will never let you merge them to master.

(*This guarantee is legally non-binding and cannot be redeemed in any way.)


Is your proposal suitable for beginners? – yes

My name is Mark Smith, although I'm known as Judy2k online. I'm a Developer Advocate for Nexmo. I love writing stupid Python code in an attempt to really understand how Python works. When I'm not doing this, you'll find me crocheting, building custom keyboards, or designing models for 3D printing.

This speaker also appears in: