4 ms·
Probably to make it easier for programmers who end lines with them as a knee jerk reaction. After a stint of java or javascript, I find myself doing it too.
by johnrob 18y ago
Probably to make it easier for programmers who end lines with them as a knee jerk reaction. After a stint of java or javascript, I find myself doing it too.
- eru 18y agoAnd you can put two or more commands on one line.
- blasdel 18y agoI use them for this purpose in both Python and Ruby when there's a formatting win to be had.
- gaius 18y agoYeah. Often it's bad style, but IMHO if you just need to do something like: x = 0; y = []; z = None Then it is actually clearer to group them together, it means more "real code" on screen at a time.
- eru 18y agoI do not know whether that was a good example to show the benefits of the semicolon: x, y, z = 0, [], None
- lehmannro 18y agoWhile the semicolon is only a convenience it has some common use cases. For example shoot-and-forget invokations of third party modules: import sys; sys.exit() import pdb; pdb.set_trace() import cgitb; cgitb.enable() import psyco; psyco.full() import pygtk; pygtk.require('2.0') And of course it's pretty useful in environments where one-liner are easier to handle: $ python -c "import mymod; mymod.test()"
- gaius 18y agoNow that I look in my code I actually have: import matplotlib; matplotlib.use('Agg'); from matplotlib import pyplot
- ulf 18y agoIn this case you could just use: x, y, z = 0, [], None