EdmontonPy
Inspired by the Python community, we hope to foster a strong, supportive, and proficient Python community in the Edmonton area.
edmontonpy.com
@edmontonpy
edmontonpy.slack.com
NEXT MEETUP ON JUNE 11TH
Pipenv: A Guide to the New Python Packaging Tool
Getting started with Python testing
How to have a great first Pycon
Python Exceptions: An Introduction
An Introduction to Python bytecode
Great Benefits of Python Type annotations
A common Mistake in python is defining the default of an optional argument in the function declaration.
def all_kitten_names(names=[]):
names.append("Ghost")
return names
>>> all_kitten_names()
['Ghost']
>>> all_kitten_names()
['Ghost', 'Ghost']
>>> all_kitten_names()
['Ghost', 'Ghost', 'Ghost']
def all_kitten_names(names=None):
if names is None:
names = []
names.append("Gambit")
return names
>>> all_kitten_names()
['Gambit']
>>> all_kitten_names()
['Gambit']
>>> all_kitten_names()
['Gambit']
Wrong Way
Right Way
output:
output:
The Reason this happens is that the default value for a function is only evaluated once. This problem arises when you don't give arguments, so do it the right way!
By EdmontonPy
Inspired by the Python community, we hope to foster a strong, supportive, and proficient Python community in the Edmonton area.