Is this valid in Python and why?

Technology CommunityCategory: PythonIs this valid in Python and why?
VietMX Staff asked 3 years ago
Problem

Consider:

def my_function():
  print my_function.what
my_function.what = "right?"
my_function() # Prints "right?"

It is valid. In Python, everything is an object, including functions. But if we don’t have what defined, we will get an Attribute error.