"++" and "-" that can be used in php and JacaScript cannot be used in python. I get a syntax error when I try to use it.
python
i=0;
while i<5:
print(i)
i++
#output
i++
^
SyntaxError: invalid syntax
Use ʻi + = 1, ʻi- = 1
python
i=0;
while i<5:
print(i)
i+=1
#output
0
1
2
3
4
processing | python | php | JavaScript |
---|---|---|---|
i++ | - | ◯ | ◯ |
i+=1 | ◯ | ◯ | ◯ |
i=i+1 | ◯ | ◯ | ◯ |
i-- | - | ◯ | ◯ |
i-=1 | ◯ | ◯ | ◯ |
i=i-1 | ◯ | ◯ | ◯ |
python
for i in range(5):
print(i)
--The python for statement retrieves consecutive things such as list and range one by one. (Foreach in php) --If you do not specify the step, the process is the same as i ++. --The php for statement repeats as long as the condition is met.
> [python] How to use for statement
php
<?php
for ($i=0; $i<5; $i++){
echo $i;
}
?>
php(Embedded in HTML)
<?php for ($i=0; $i<5; $i++): ?>
<?php echo $i; ?>
<?php endfor; ?>
}
php needs ";" after each process. Python considers the process to end with a line break.
Recommended Posts