1

In the following code:

In [5]: if 2 > 1 & 1 > 0:
   ...:     print("True")
   ...:     
True

I know that: > is comparative operator,
& is logic/bitwise operator,
= is assignment operator,

How about colon : ? How could I name it an abstract concept rather than colon:

In [6]: def foo(): return 3
In [7]: foo()
Out[7]: 3

In the above codes, : act as = assignment.

I checked the official docs2. Lexical analysis — Python 3.6.6 documentation

2.6. Delimiters
The following tokens serve as delimiters in the grammar:

(       )       [       ]       {       }
,       :       .       ;       @       =       ->
+=      -=      *=      /=      //=     %=      @=
&=      |=      ^=      >>=     <<=     **=
The period can also occur in floating-point and imaginary literals. 

I noticed that all the delimiters have appropriate meaning: ( for tuple, [ for list constructor, @ for decorator, , for true delimiter, . for attribute access.

Excluding :?

How could I name it in a meaning way?

AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
  • The colon in end of the line of the code block is for `indentation`. May be you can look into https://stackoverflow.com/questions/215581/what-is-the-purpose-of-the-colon-before-a-block-in-python – niraj Sep 24 '18 at 03:10
  • FYI `&` is only the bitwise operator. `and` is the logic operator. – Mark Tolonen Sep 24 '18 at 03:12
  • If there's no explicit name in the language definition, then it might have none and you just call it "colon". – Klaus D. Sep 24 '18 at 03:14

1 Answers1

1

: is simply part of the syntax of a compound statement that indicates the end of the clause header.

From the documentation of compound statements:

Compound statements consist of one or more ‘clauses.’ A clause consists of a header and a ‘suite.’ The clause headers of a particular compound statement are all at the same indentation level. Each clause header begins with a uniquely identifying keyword and ends with a colon.

blhsing
  • 91,368
  • 6
  • 71
  • 106