Skip to content

Instantly share code, notes, and snippets.

@MattSegal
Last active July 20, 2017 03:40
Show Gist options
  • Save MattSegal/92edb226d275ffc5d325e095dd0e768c to your computer and use it in GitHub Desktop.
Save MattSegal/92edb226d275ffc5d325e095dd0e768c to your computer and use it in GitHub Desktop.
from __future__ import print_function # Ignore this
# Example 1 - Function with argument
def say_hello(name):
# Prints 'Hello {name}!' to the screen
print("Hello {}!".format(name))
# We 'invoke' / 'call' a function using the ()s
say_hello('Nick')
# If you want to assign the function to a variable, just don't do the ()s
a_variable = say_hello
# Then you can invoke it using ()s
a_variable('Matt')
# Example 2 - Function with no argument
def say_hello_to_stranger():
# Prints 'Hello stranger!' to the screen
print("Hello stranger!")
say_hello_to_stranger()
some_variable = say_hello_to_stranger
some_variable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment