Skip to content

Instantly share code, notes, and snippets.

@CharudattaManwatkar
Last active April 30, 2021 20:15
Show Gist options
  • Save CharudattaManwatkar/838948283851096b68f89f126537f884 to your computer and use it in GitHub Desktop.
Save CharudattaManwatkar/838948283851096b68f89f126537f884 to your computer and use it in GitHub Desktop.
Function attributes in python
def func(x):
intermediate_var = x**2 + x + 1
if intermediate_var % 2:
y = intermediate_var ** 3
else:
y = intermediate_var **3 + 1
# setting attributes here
func.optional_return = intermediate_var
func.is_awesome = 'Yes, my function is awesome.'
return y
y = func(3)
print('Final answer is', y)
# Accessing function attributes
print('Show calculations -->', func.optional_return)
print('Is my function awesome? -->', func.is_awesome)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment