Skip to content

Instantly share code, notes, and snippets.

@duruyao
Last active November 2, 2022 09:59
Show Gist options
  • Save duruyao/eba4128e08f56950f99b25bc2348263a to your computer and use it in GitHub Desktop.
Save duruyao/eba4128e08f56950f99b25bc2348263a to your computer and use it in GitHub Desktop.
Python3 project coding style example.
#!/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