Newbie Question.. What is the replacement for the ELSE command?.

Peter Hansen peter at engcorp.com
Fri Sep 14 20:02:50 EDT 2001


Cable wrote:
> 
> I am trying to teach myself Python.  All the online tutorials, have
> examples with the else command.  I cant get it to work is there a
> replacement?

When posting problem reports, it is necessary to post the _specific_
code you are trying to run, and preferably the details of the error
message generated.  The best approach is to use the interactive 
prompt, then cut and paste from your console window into your mail
message.  For example:

Python 2.0 (#1, Dec 20 2000, 15:28:16)
[GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> def test():
...     if 1==2:
...         print 'yikes!'
...     else
  File "<stdin>", line 4
    else
       ^
SyntaxError: invalid syntax
>>> def test():
...     if 1==2:
...         print 'yikes!'
...     else:
...         print 'phew!'
...
>>> test()
phew!

(In the unlikely event you were missing the colon after else,
please read the above two functions carefully.)

Cheers,
-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list