Welcome to MadPy!

Organizers¶
![]() |
![]() |
![]() |
Ed Rogers |
David Hoese |
Josh Karpel |
Code of Conduct¶
MadPy is a community group and open to all experience levels. We are committed to a safe, professional environment
Our Commitment to You¶
We are enthusiastically focused on improving our event and making it a place that is welcoming to all. All reports will be taken seriously, handled respectfully, and dealt with in a timely manner.
Learn more about the MadPy Code of Conduct:
Python Warm-Up¶
A get function with a default:¶
In [1]:
madpy_menu = {
"pizza": "Ian's",
"beverage": "Sprite",
}
In [2]:
def get_menu_item(key, default=None):
value = madpy_menu.get(key)
if value is None:
return default
return value
In [3]:
get_menu_item("pizza")
Out[3]:
"Ian's"
In [4]:
get_menu_item("salad", default="Sorry, not tonight!")
Out[4]:
'Sorry, not tonight!'
Trouble with the get function:¶
In [5]:
madpy_menu = {
"pizza": "Ian's",
"beverage": "Sprite",
"dessert": None,
}
In [6]:
def get_menu_item(key, default=None):
value = madpy_menu.get(key)
if value is None:
return default
return value
In [7]:
get_menu_item("salad", default="Sorry, not tonight!")
Out[7]:
'Sorry, not tonight!'
In [8]:
get_menu_item("dessert", default="Sorry, not tonight!")
Out[8]:
'Sorry, not tonight!'
Can't distinguish between not being on the menu, and being on the menu and None-valued!
Using a "sentinel" value¶
In [9]:
madpy_menu = {
"pizza": "Ian's",
"beverage": "Sprite",
"dessert": None,
}
In [10]:
MISSING = object()
def get_menu_item(key, default=None):
value = madpy_menu.get(key, MISSING)
if value is MISSING:
return default
return value
In [11]:
get_menu_item("salad", default="Sorry, not tonight!")
Out[11]:
'Sorry, not tonight!'
In [12]:
get_menu_item("dessert", default="Sorry, not tonight!") is None
Out[12]:
True
In [13]:
print(MISSING)
<object object at 0x7bf5c437d710>
Can we make it prettier?¶
In [14]:
madpy_menu = {
"pizza": "Ian's",
"beverage": "Sprite",
"dessert": None,
}
In [15]:
from enum import StrEnum
class Missing(StrEnum):
MISSING = "MISSING"
def get_menu_item(key, default=None):
value = madpy_menu.get(key, Missing.MISSING)
if value is Missing.MISSING:
return default
return value
In [16]:
get_menu_item("salad", default="Sorry, not tonight!")
Out[16]:
'Sorry, not tonight!'
In [17]:
get_menu_item("dessert", default="Sorry, not tonight!") is None
Out[17]:
True
In [18]:
print(Missing.MISSING)
MISSING
New in Python 3.15 (to be released in October 2026)¶
In [19]:
from sys import version
print(version)
3.15.0b2 (main, Jun 2 2026, 22:26:04) [Clang 22.1.3 ]
In [20]:
from builtins import sentinel
MISSING = sentinel("MISSING")
In [21]:
madpy_menu = {
"pizza": "Ian's",
"beverage": "Sprite",
"dessert": None,
}
In [22]:
MISSING = sentinel("MISSING")
def get_menu_item(key, default=None):
value = madpy_menu.get(key, MISSING)
if value is MISSING:
return default
return value
In [23]:
get_menu_item("salad", default="Sorry, not tonight!")
Out[23]:
'Sorry, not tonight!'
In [24]:
get_menu_item("dessert", default="Sorry, not tonight!") is None
Out[24]:
True
In [25]:
print(MISSING)
MISSING








