August 29th, 2004, 02:17 PM
-
invalid syntax
hey all i'm new member here and i have problem with python2.3
i wanted to write this code for example
h='hello'
if 'n' in h:
print ' n is in hello'
else:
print' n is not in hello'
when i try to check or this code i got this message
invalid syntax and it show else in red quarter
although this is exmaple in the support.pdf file i'm newbie to python and i don't know what is wrong
i hope i get helo soon
bye
August 29th, 2004, 02:52 PM
-
Please post your code in CODE /CODE brackets when posting. You can do this by pressing the '#' button in the post editor. This will preserve any indentation you have in your code. Otherwise, indentation is lost. And that seems to be the only problem I can find with the code you gave: indentation. Indentation is a part of the Python syntax, so you MUST properly indent or else!
Your code should look like this:
Code:
h = 'hello'
if 'n' in h:
print ' n in hello'
else:
print ' n is not in hello'
Code:
print' n is not in hello'
Also be sure to put a space between print and your quotation. While this does not generate an error, it reduces readability.
If this doesn't solve the problem, in your reply, also be sure to post a copy of your error report.
Derrick
August 30th, 2004, 07:42 AM
-
thanks derrick for replying me
but it still gives me this error invalid syntax
and i don't know what is wrong i copied and paste the code which was in support.pdf file and it didn't work
i tried to writie it in python shell and in python command line and still gives me this error
Invalid syntax
i guess i should download python 2.4 alpha maybe it won't show me the error
thanks derrick again
for ur tips
August 30th, 2004, 06:44 PM
-
Changing to 2.4 will not make any difference, since the problem is with your code not with Python.
I don't know what the support.pdf file is since it is not part of standard Python, but cutting and pasting from a PDF file is likely to screw up the indentation, so that is probably the cause of your problem. Please read p4j's post again, since he has explained it once already. Try cutting and pasting the code he gave you, and you will see that it works fine.
Dave - The Developers' Coach