The story of Python without increment and decrement operators.

When I write Python in parallel with C or Java code, I sometimes want to write operators like i ++ and i-- for increments and decrements ...

However, as you can see by trying this, an error will occur.

>>> i=1  
>>> i++
SyntaxError: invalid syntax

There seems to be some theory as to why operators like "++" and "-" are not implemented in Python, but they are the creators of Python [benevolent dictator](http: // www. Former Google engineer Guido van Rossum, artima.com/weblogs/viewpost.jsp?thread=235725), understands Python for both writers and readers without giving complex meanings to "+" and "-". It seems that he wanted to make it easy.

By the way, languages like Ruby and Scala don't have these operators either. There seem to be various reasons for "not" here either ...

Anyway, I personally appreciate the specifications because I don't have to worry about the errors caused by the front and back.

In Python, there is no problem if you write as follows.

>>> i+=1 #Increment
>>> print(i)  
2  
>>> i-=1 #Decrement
>>> print(i)  
1  

Also, regarding frequently used for statements

>>> for(int i=0; i<10; i++)

not

>>> for i in range(0, 10)

You just have to write.

By the way, you don't usually see it, but you can write it as follows by using complement. If you want to write ...

>>> i=-~1
>>> print(i)
2

As a bonus, the character increment (?) Can be written as:

>>> print(chr(ord('a')+1))
b

reference

[LINUX Shugendo-Increment of PYTHON! ](Https://linuxshugendo.wordpress.com/2014/02/28/python-%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%AF%E3%83%AA % E3% 83% A1% E3% 83% B3% E3% 83% 88% EF% BC% 81 /) Why are there no ++ and --​ operators in Python? Weekend Kyoto-Character Increment

Recommended Posts

The story of Python without increment and decrement operators.
The story of Python and the story of NaN
The story of running python and displaying the results without closing vim
The story of making Python an exe
The story of manipulating python global variables
The story of trying deep3d and losing
The story of blackjack A processing (python)
The story of low learning costs for Python
Summary of the differences between PHP and Python
The answer of "1/2" is different between python2 and 3
Specifying the range of ruby and python arrays
Compare the speed of Python append and map
Image processing? The story of starting Python for
The story of reading HSPICE data in Python
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
the zen of Python
The story of sys.path.append ()
The process of installing Atom and getting Python running
Python --Explanation and usage summary of the top 24 packages
Visualize the range of interpolation and extrapolation with python
The story of FileNotFound in Python open () mode ='w'
Referencing and changing the upper bound of Python recursion
I checked out the versions of Blender and Python
The story of automatic language conversion of TypeScript / JavaScript / Python
The story of building Zabbix 4.4
Towards the retirement of Python2
[Apache] The story of prefork
About the ease of Python
About the features of Python
Source installation and installation of Python
The Power of Pandas: Python
The story of implementing the popular Facebook Messenger Bot with python
[Python] Heron's formula functionalization and calculation of the maximum area
The story of how the Python bottle worked on Sakura Internet
The story of introducing jedi (python auto-completion package) to emacs
[python] plot the values ​​before and after the conversion of yeojohnson conversion
The story of rubyist struggling with python :: Dict data with pycall
The process of making Python code object-oriented and improving it
The websocket of toio (nodejs) and python / websocket do not connect.
I want to know the features of Python and pip
[Tips] Problems and solutions in the development of python + kivy
[Python] Tensorflow 2.0 did not support Python 3.8, so the story of downgrading Python
Play with the password mechanism of GitHub Webhook and Python
Environment construction of python and opencv
I compared the speed of Hash with Topaz, Ruby and Python
The story that the version of python 3.7.7 was not adapted to Heroku
Count the number of Thai and Arabic characters well in Python
Installation of SciPy and matplotlib (Python)
[Python] The stumbling block of import
Note: Get the first and last items of Python OrderedDict non-destructively
First Python 3 ~ The beginning of repetition ~
Python: Update pyenv without thinking and solve the "where is Python?" Phenomenon
March 14th is Pi Day. The story of calculating pi with python
The story of participating in AtCoder
A story that struggled to handle the Python package of PocketSphinx
[Introduction to Python] I compared the naming conventions of C # and Python.
Existence from the viewpoint of Python
[Python] How to get the first and last days of the month
pyenv-change the python version of virtualenv
[Python] I thoroughly explained the theory and implementation of logistic regression