Skip to content

Instantly share code, notes, and snippets.

@Glench
Last active December 15, 2015 12:59
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 Glench/5264091 to your computer and use it in GitHub Desktop.
Save Glench/5264091 to your computer and use it in GitHub Desktop.
A new-to-programming student asked me why you would use functions. I gave this example and I feel like this explains it well, building up abstraction from a concrete example to a more powerful, general one. For the record, you shouldn't use '+' to put strings together and you shouldn't do language translation this way. This is just to illustrate…
def say_hello_glen():
return 'hello, glen'
def say_hello(name):
return 'hello, ' + name
def greet(name, language):
if language is 'spanish':
return 'hola, ' + name
if language is 'english':
return 'hello, ' + name
else:
return 'heeeey'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment