Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the term for a colon before a suite in Python syntax?

I want to know what the technical term for a colon in the context of introducing a suite after a statement is called. I do not mean colons in slices, key-value pairs or type hints, but this kind of usage:

if True:
    pass
else:
    pass

try:
    raise
except:
    pass

def foo():
    pass

lambda: ...  # I don't know if this is appertaining

I did not really find a fitting term online. Most only call them colons, while expecting the reader to understand the meaning of a colon in this context in Python. I found this website which uses the term "colon operator", but that doesn’t feel right to me – especially as it lumps together all uses of colons under that umbrella term. I apologise if I have missed an obvious answer somewhere.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s simply called a "colon" :, but I might say and the grammar spec suggests you’d say something like "the start of a block"

https://docs.python.org/3/reference/grammar.html

# COMPOUND STATEMENTS
# ===================

# Common elements
# ---------------

block:
    | NEWLINE INDENT statements DEDENT 
    | simple_stmts
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading