Last active
September 2, 2024 04:42
-
-
Save duruyao/eba4128e08f56950f99b25bc2348263a to your computer and use it in GitHub Desktop.
A Python3 static coding style example.
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
#!/usr/bin/env python3 | |
from typing import Union, Optional, Dict | |
def multiply(arg1: Union[int, float, str, None] = 0.0, | |
arg2: Union[int, float, str, None] = 0.0) -> Optional[Dict[str, Union[int, float, str]]]: | |
""" | |
Calculate the product of two numbers. | |
:param arg1: a factor (default: 0.0) | |
:param arg2: a factor (default: 0.0) | |
:return: return None if an input number is None, else | |
return a Dictionary like {'int': 3, 'float': 3.14, 'str': '3.14'} | |
""" | |
if None in (arg1, arg2): | |
return None | |
result = float(arg1) * float(arg2) | |
return {'int': int(result), 'float': result, 'str': str(result)} | |
def main(): | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment