Operators ++,-cannot be used in python (difference from php)

Operators ++,-cannot be used in python

"++" 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.

error

python


i=0;
while i<5:
   print(i)
   i++

#output
i++
   ^
SyntaxError: invalid syntax

approach

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

I wondered if i ++ could be used with the for statement, but there was no problem because the writing method of the for statement was completely different between php and python.

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

Operators ++,-cannot be used in python (difference from php)
[Memorandum] Japanese keys cannot be used in python string.Template.substitute
list comprehension because operator.methodcaller cannot be used in python 2.5
[Redash] Standard library cannot be used in python function
New features in Python 3.9 (1)-Union operators can be used in dictionary types
Modules cannot be imported in Python on EC2 run from AWS Lambda
++ and-cannot be used for increment / decrement in python
Python note: When the pip command cannot be used
Convert date timezone (time difference) in Python (from string)
Can be used in competition pros! Python standard library
Cheating from PHP to Python
Find the difference in Python
Nesting ternary operators in python
Video cannot be loaded with Spyder in Python development environment
Pharmaceutical company researchers have summarized the operators used in Python
Scripts that can be used when using bottle in Python
Difference between list () and [] in Python
Difference between == and is in python
8 Frequently Used Commands in Python Django
Get data from Quandl in Python
[Python] It seems that global variables cannot be referenced in Multiprocessing
[Python] Basic knowledge used in AtCoder
33 strings that should not be used as variable names in python
Investigating what could be used as a Markdown parser in Python
Extract text from images in Python
Python standard input summary that can be used in competition pro
Jupyter Notebook 6.0.2 cannot be installed in the Python 2.7 environment created in Anaconda
Extract strings from files in Python
I tried to put PyCharm in Ubuntu 16.04 LTS (PPA cannot be used)
Avoid nested loops in PHP and Python
Get exchange rates from open exchange rates in Python
difference between statements (statements) and expressions (expressions) in Python
Revived from "no internet access" in Python
Prevent double boot from cron in Python
Difference between PHP and Python finally and exit
[python] Frequently used techniques in machine learning
Difference between @classmethod and @staticmethod in Python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
Download images from URL list in Python
Get battery level from SwitchBot in Python
Python modules with "-(hyphen)" cannot be removed
Tkinter could not be imported in Python
Generate a class from a string in Python
Generate C language from S-expressions in Python
Convert from Markdown to HTML in Python
Get Precipitation Probability from XML in Python
Get metric history from MLflow in Python
A solution to the problem that the Python version in Conda cannot be changed
I made a familiar function that can be used in statistics with Python
Let's look at a differential equation that cannot be solved normally in Python
Correspondence memo when the direction key cannot be used on the python command line
De-VBA Excel tool! Eliminate VBA tool with Python in environment where Python cannot be installed
Get time series data from k-db.com in Python
Project cannot be created with Python3.5 (Windows) + django1.7.1
Functions that can be used in for statements
"Temporary solution" when pip cannot be updated [Python]
Techniques often used in python short coding (Notepad)
From file to graph drawing in Python. Elementary elementary
Python environment settings (virtualenv + pip cannot be done)
About the difference between "==" and "is" in python