我正在尋找for
循環類似於其他語言PERL/TCL/C++在Python中。TCL喜歡for循環在python
下面像TCL是在Python for循環
for { set i 0 } { $i < $n } { incr i} {
#I like to increment i value manually too like
if certain condition is true then increment
set i = [expr i+1] # in some cases
print i
我有同樣的方式了。在蟒蛇下面我所知道的是for循環語法
for i in var1
#How to increment var1 index manually in some scenarios
在你的例子中用'range(0,n,1)' –
替換'var1' @DaleWilson:每次增加1。但如果我們想根據條件增加一些場景,例如增加2 – Nitesh
[我如何在Python中使用C風格的循環?](https://stackoverflow.com/questions/9450446/how-do -i-use-ac-style-for-loop-in-python) – Aurora0001