您应该在函数_602_1">函数中编写所有代码。并在主函数中调用它。例如:
# Import necessary libraries.
# Define your functions from the top
def Foo():
print('foo')
def Bar():
print('bar')
if __name__ == '__main__':
# Run your code from here,call the needed functions.
Foo()
Bar()
# If you don't want to run Bar(),simply comment it.
定义/函数是最好的方法。
def afunc():
print('This is the function printed after the other function')
def func(): # Starts the definition
print('This is a function')
afunc()
func() # Runs the Code
我没有专门使用 ,但我知道在许多其他 IDE(VS Code、、)中,您可以将脚本分解为单元格并单独运行每个单元格。
对于 VS Code 和 ,您可以通过包含以 #%% 开头的行来指定不同的单元格