Inspired by the inline-repl feature from Simple GHC (Haskell) Integration for VSCode, the extension python-inline-repl can run Python codes within comments and preserve the result in your file.
You can use variables and functions defined in your file.
You can re-run the code after modification to overwrite the result.
You can write the spec for a function using examples.
Just enabel the extension and open a Python file!
Enjoy!