Python Forum

Full Version: another way to make Python easier
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Python already accepts an extra comma after the last item of a source sequence of expressions, such as forming a list:
mylist = [
'foo',
'bar',
]
that allows scripts that generate to need to deal with skipping the code that outputs the comma after the last item, for example.

another idea i have applies to having an "if" statement followed by a bunch of "elif" statements. the idea is to allow "elif" as an alternative of "if" for a similar reason... so the code generator does not have to check if this is the first.
It doesn't work, the grammar becomes ambiguous.
if a:
   ...
if b:
   ...
elif c:
   ...
cannot be equivalent to
if a:
   ...
elif b:
   ...
elif c:
   ...