Skip to content

Instantly share code, notes, and snippets.

@JeffCohen
Created January 17, 2015 16:49
Show Gist options
  • Save JeffCohen/3f328abf0cecbf29ff2c to your computer and use it in GitHub Desktop.
Save JeffCohen/3f328abf0cecbf29ff2c to your computer and use it in GitHub Desktop.
Why does python let me do this?
# Python 3.4
# A nice class
class Person:
def __init__(self, name):
self.name = name
# A nice function
def speak():
print("Woof!")
# A nice person
jeff = Person("Jeff")
# A bad thing!
jeff.s = speak
jeff.s() # => "Woof!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment