Last active
January 19, 2021 22:57
-
-
Save sojohnnysaid/6a70fe00b03c6ff34a0c0db328262341 to your computer and use it in GitHub Desktop.
getting started with python decorators
This file contains hidden or 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 plusNineThousandDecorator(function): | |
| def wrapper(number): | |
| return function(number) + 9000 | |
| return wrapper | |
| @plusNineThousandDecorator | |
| def returnPositiveNumber(number): | |
| if number > 0: | |
| return number | |
| else: | |
| return 1 | |
| print(returnPositiveNumber(42)) | |
| # results | |
| # 9042 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment