Created
July 7, 2012 02:41
-
-
Save bradmontgomery/3064005 to your computer and use it in GitHub Desktop.
Is this too clever?
This file contains hidden or 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 accepts_two_types(v): | |
if type(v) == type(1): | |
print "%s is an integer" % (v) | |
elif type(v) == type(''): | |
print "%s is assumed to be a string" % (v) | |
else: | |
raise TypeError, "not a string or int!" | |
if __name__ == "__main__": | |
accepts_two_types(42) | |
accepts_two_types("forty two") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment