python中缩进在程序中_有没有办法将Python代码中的缩进转换为大括号?
生活随笔
收集整理的这篇文章主要介绍了
python中缩进在程序中_有没有办法将Python代码中的缩进转换为大括号?
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
Python支持用于定义代码块的大括号,并且它还支持使用“开始”和“结束”标记。
请看这些代码示例:class MyClass(object): #{
def myfunction(self, arg1, arg2): #{
for i in range(arg1): #{
print i
#}
#}
#}
还有一个带有bash样式的例子:fi = endclass = enddef = endclass = done = None
class MyClass(object):
def myfunction(self, arg1, arg2):
for i in range(arg1): #do
if i > 5: #then
print i
fi
done
enddef
endclass
这方面最好的一点是,你可以忘记在其中放置一个近距括号,而它仍然是有效的python!class MyClass(object): #{
def myfunction(self, arg1, arg2): #{
for i in range(arg1): #{
print i
# whoops, forgot to close that bracket!
#}
#}
总结
以上是生活随笔为你收集整理的python中缩进在程序中_有没有办法将Python代码中的缩进转换为大括号?的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: android monkey压力测试,A
- 下一篇: 用python开启相机_如何用Pytho