Python 到 reduce/expand 我的代码有什么方法类似于“{}”的R函数吗?

Is there any way in Python to reduce/expand my code similar to the R function of "{ }"?

我在Python 3.7 中编写了相当复杂的程序。但是,我正在寻找一种方法来减少(然后再次扩展)我已经可以使用的功能。这样我就不必在想回到顶部时滚动超过 200 行代码。

正如我所说,我在 Python 3.7 中编写我的代码,这似乎是一种很好的 easy/beginner 技术。然而,我尝试用谷歌搜索很多东西,不幸的是英语不是我的母语,我不知道要做什么google。谷歌搜索 "reduce code in Python" 对我没用。因此,我希望你们极客能帮助我! :)

例如

而不是

1 # This is some random code

2 print("Hello")

3 print("beautiful")

4 print("World")

5 # This is some random code

我想要

1 # This is some random code

2-4 # Here all the other lines should be reduced to one line

5 # This is some random code

在 IDE 中使用代码折叠。可以找到 Anaconda 的建议 IDES here。我推荐 Visual Studio 代码。