C
Chang LI
Some statements use : in the tail such as while x > 0: and def func():
What is the meaning and the usage of : in Python?
What is the meaning and the usage of : in Python?
Chang said:Some statements use : in the tail such as while x > 0: and def func():
What is the meaning and the usage of : in Python?
Some statements use : in the tail such as while x > 0: and def func():
What is the meaning and the usage of : in Python?
Paul Robson said:while i > 0 do
begin
writeln i;
i := i - 1;
end;
while i > 0:
print i
i = i - 1
Chang said:So the : is similar to "begin"
Correct
and the last space line is similar to "end", right?
> How about
while i > 0 :
print i
i = i-1
Dave said:this is answered in the python faq:
http://www.python.org/doc/faq/gener...equired-for-the-if-while-def-class-statements
bruno said:<please-someone-correct-me-if-i-am-wrong>
In fact, from a purely technical POV, the ':' could have been omitted
from the Python syntax, since indentation does the whole job of defining
blocks. It's only here for readability AFAIK.
</please-someone-correct-me-if-i-am-wrong>
Correct
.... print iNope. You don't need a space line (you mean an empty line by that,
right?), you can just outdent one level and continue without any empty
lines (although in the interactive interpreter you need the empty line
to end the block on the first indentation level). So you could do:
i = 5
while i > 0:
print i
i = i-1
print "That's it"
Without the ':', single-line suites are impossible. If you allow only
multi-line suites, you're right.
Jeremy said:The only punctuation you *need* is whitespace. See Forth
are they really?
if <expression> <expressions>
and the likes would invho parse just fine
I always thought the rule was "the less useless symbols, the higher the
readability." I.e:
The only punctuation you *need* is whitespace. See Forth (I don't know
if this is perfect but I'd bet the transform is simple),
Greg> You don't even need that... see FORTRAN.
<please-someone-correct-me-if-i-am-wrong>
In fact, from a purely technical POV, the ':' could have been omitted
from the Python syntax, since indentation does the whole job of defining
blocks. It's only here for readability AFAIK.
</please-someone-correct-me-if-i-am-wrong>
BJörn Lindqvist said:Because it contains more non-significant symbols (, ), { and } that
"steal" the programmers attention. But consider
def f(x, y, z)
print x, y, z
to
def f(x, y, z):
print x, y, z
IMHO, the colon-less variant is more readable than the one with the colon.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.