Space Sensitive?

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Tue Jun 6 13:27:09 EDT 2000


Akira Kiyomiya wrote in comp.lang.python:
> I hear Python is space sensitive, however, "Learning Python" from O'Reilly
> and "Python Essential Reference" from New Riders do not cover this topic.
> 
> Could someone explain this one with a nice simple example why Python is
> space sensitive?

It means that Python tells to which block a statement belongs by looking at
the indentation.

if something:
   print "Hello!"
   x = 3
   
Is different from

if something:
   print "Hello!"
x = 3

In the second case, 'x = 3' doesn't belong to the if statement. This:

if something:
   print "Hello!"
  x = 3

Is a syntax error.

It means you have to use some consistent indenting, and that the code isn't
filled with all those { { } } thingies. No big deal, really.

-- 
Remco Gerlich,  scarblac at pino.selwerd.nl

   This is no way to be
     Man ought to be free      -- Ted Bundy
       That man should be me



More information about the Python-list mailing list