How can one create new scopes in python

后端 未结 12 1231
渐次进展
渐次进展 2020-12-10 01:08

In many languages (and places) there is a nice practice of creating local scopes by creating a block like this.

void foo()
{
     ... Do some stuff ...

             


        
12条回答
  •  清歌不尽
    2020-12-10 01:53

    If you just want to create temp variables and let them be garbage collected right after using them, you can use

    del varname
    

    when you don't want them anymore.

    If its just for aesthetics, you could use comments or extra newlines, no extra indentation, though.

提交回复
热议问题