On 23/02/2023 00:58, avi.e.gr...@gmail.com wrote:
So can anyone point to places in Python where a semicolon is part of a best
or even good way to do anything?


Yes.  Take this bit of toy code which I just dreamed up.  (Of course it is toy code; don't bother telling me how it could be written better.)  If it looks a bit ragged, pretend it is in a fixed font.

if dow==0: day="Mon"; calcPay()
if dow==1: day="Tue"; calcPay()
if dow==2: day="Wed"; calcPay()
if dow==3: day="Thu"; calcPay()
if dow==4: day="Fri"; calcpay()
if dow==5: day="Sat"; calcPay(rate=1.5)
if dow==6: day="Sun"; calcPay(rate=2)

The point is: when you have several short bits of code with an identical or similar pattern, *vertically aligning* the corresponding parts can IMO make it much easier to read the code and easier to spot errors.
Compare this:

if dow==0:
    day="Mon"
    calcPay()
if dow==1:
    day="Tue"
    calcPay()
if dow==2:
    day="Wed"
    calcPay()
if dow==3:
    day="Thu"
    calcPay()
if dow==4:
    day="Fri"
    calcpay()
if dow==5:
    day="Sat"
    calcPay(rate=1.5)
if dow==6:
    day="Sun"
    calcPay(rate=2)

Not so easy to spot the mistake now, is it?
Not to mention the saving of vertical space.

Best wishes
Rob Cliffe
PS If you really care, I can send you a more complicated example of real code from one of my programs which is HUGELY more readable when laid out in this way.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to