Created
July 14, 2015 20:26
-
-
Save amackera/80704175fb51cee9be62 to your computer and use it in GitHub Desktop.
Examples of return
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def addNumbers(x, y): | |
# Returning a value | |
return x + y | |
def printString(string): | |
# Not returning anything, but just printing to console | |
print string | |
def returningEarly(myList): | |
# This function only operates on lists longer than 2 elements | |
if len(myList) <= 2: | |
return | |
else: | |
# other stuff would happen here, too lazy | |
... | |
# I want to add some numbers | |
sum = addNumbers(1, 2) | |
# sum is now 3 | |
# I want to print something | |
printString('Hello Alex!') | |
# prints 'Hello Alex!' to console |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment