如何使用Visual Studio Code在python中分离代码块?



我习惯于用SQL编码,我可以使用";"符号来分隔两段代码,并在一个文件上单独运行它们。这使得测试代码的特定部分变得非常容易。但是,在python中,我还没有找到一种方法来测试我的代码,而无需创建新文件并复制和粘贴代码。我正在使用VS工作室代码。

亲切问候

使用函数。

函数是封装要重复运行或在特定上下文中运行的代码块的好方法。对于您的应用程序,您可以执行以下操作:

def firstPieceOfCode():
# do first job when called
...
def secondPieceOfCode():
# do second job when called
...
secondPieceOfCode() # only do second job for now

最新更新