0

I have the following method,

def MySampleMethod():
    return "Sample method called"

I tried the following code,

MySampleMethod.variablename = "Some data"
print MySampleMethod.variablename 

The code executed without error and printed "Some data".

How is it possible to assign a variable to a function and how it works ?

Kajal
  • 709
  • 8
  • 27
  • Because everything in python is an object, including functions. **BUT** keep in mind that the fact you can do something, doesn't mean you *should* do it... Allow me to make a bit of [Spam](https://stackoverflow.com/a/48031685/289011) of my own answer... **:-D** – Savir Jan 04 '18 at 05:42
  • 1
    Thank you so much BorrajaX. It was really informative. – Kajal Jan 04 '18 at 07:23

0 Answers0