Suggestion: add "end" as a keyword for marking end of blocks

I would seriously recommend just getting used to how python actually works.

At best you are going to come up with a solution that confuses every other person that ever needs to look at your code.

Millions of people have learned the existing syntax. I’m sure you can do it too.


That is exactly equivalent to doing it with a string constant. Any value is a value.

Are you sure of that? Why wouldn’t it?

That’s not how it works. You didn’t put a literal there; you put a name. So it’s just like any other name, and has to be looked up.

(By the way, it’s unlikely Python will optimize away name lookups, since deliberately triggering a NameError is one of the easiest ways to test whether you’re on a Python version that provides some feature.)

If you really need trainer wheels while you get familiar with Python, use #end and move on. That way, everyone knows that it’s just trainer wheels, and won’t wonder if it has some greater purpose. But you would do well to get accustomed to Python’s style.

1 Like

Well, because I tested it. Asking would’ve been a lot nicer, BTW. No need to be rude.

$ cat 
end = pass

def print_even(limit):
        for x in range(limit):
                if x % 2 == 0:


$ python 
  File "/home/baltasarq/Downloads/", line 1
    end = pass
SyntaxError: invalid syntax

I don’t need “trainer wheels”: I’ve been using Python since around 2012. I clearly stated the objective in the first message of this thread: improving readability. Clearly this improvement in readability is not shared by most people in this forum, but there is no need for such demeanor behaviour.

Ah, I thought you meant using “pass” instead of “end”, which absolutely WOULD work. But since “pass” is not a value, it can’t be put into a variable.

I didn’t know that, and frankly, these sorts of ideas usually come from those who are looking for trainer wheels, not people who have a decade of experience with it. Forgive me for misinterpreting your experience level here.

Just my 2 cents, I usually use comments to mark the end of a block while brainstorming. The code is being modified too much, and it helps avoid mixing indentation:

But, I wouldn’t use just “end.” To me, it seems too verbose in production code. I’m just noting that I also use many code preprocessing scripts to help in faster coding, but I wouldn’t want these in the final production code.

ideas comes to mind. Maybe it would allow experimenting with this.

I see that your comments carry more information than just the end of the block.

That’s another scenario in which it would be beneficial.

Interesting. This reminds of Basic and many of its derivatives. For instance, one can find wend to end a while block, or more recently (Visual Basic), End If, End While, etc.

Too verbose? I guess that would discard endif, and such if existed. Am I wrong? Or do you somehow mean the generated code?

Yes, the code that has passed the debugging (and testing) phase is cleaned automatically. I strive for it to be readable, less code is more readable.

So, in the end, I would say that simply a comment would suffice. I wouldn’t want to see traces of the struggles that the developer has endured to create the final code. Everyone has their own tools and behaviors.

Let’s make an analogy. We use whatever tools make writing easier for us, e.g., dictionaries, grammar checkers, phraseological books, etc. But none of these are part of the final article.