Last active
April 30, 2021 20:15
-
-
Save CharudattaManwatkar/838948283851096b68f89f126537f884 to your computer and use it in GitHub Desktop.
Function attributes in python
This file contains 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 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