Skip to content

Instantly share code, notes, and snippets.

@fredrick
Created September 28, 2011 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrick/1248219 to your computer and use it in GitHub Desktop.
Save fredrick/1248219 to your computer and use it in GitHub Desktop.
Optional function arguments in Python
def hello(f, k=None):
"""
@param f is required
@param k is optional
"""
if (k == None): return '%s, hello world!' % f
else: return 'Hello %s!, said %s' % (f, k)
print(hello('Tony'))
print(hello('Tony', 'Fred'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment