LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-06-2009, 05:48 AM   #1
Python_user
LQ Newbie
 
Registered: Sep 2009
Posts: 1

Rep: Reputation: 0
[python] syntax Error : invalid syntax


Hey Guys, I just started with Python scripting.
Please find below the small snippet of if block, When I am trying to go for else if condition ,python shell giving me an error called invalid syntax.

>>>
>>> a, b = 0, 1
>>> if a == 0:
a = 1
print 'Reassigned a to 1'
elif b == 1:

SyntaxError: invalid syntax
>>>

Last edited by Python_user; 09-06-2009 at 05:50 AM.
 
Old 09-06-2009, 08:03 AM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Quote:
Originally Posted by Python_user View Post
Hey Guys, I just started with Python scripting.
Please find below the small snippet of if block, When I am trying to go for else if condition ,python shell giving me an error called invalid syntax.

>>>
>>> a, b = 0, 1
>>> if a == 0:
a = 1
print 'Reassigned a to 1'
elif b == 1:

SyntaxError: invalid syntax
>>>
What is the key (or keys combination) did you use after the elif b == 1: command?

Last edited by quanta; 09-06-2009 at 10:45 PM.
 
Old 09-06-2009, 12:52 PM   #3
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by Python_user View Post
Hey Guys, I just started with Python scripting.
Please find below the small snippet of if block, When I am trying to go for else if condition ,python shell giving me an error called invalid syntax.

Code:
>>> a, b = 0, 1
>>> if a == 0:
	a = 1
	print 'Reassigned a to 1'
	elif b == 1:
		
SyntaxError: invalid syntax
Please use CODE tags to post code. Showing the indentation is very important in Python.

The elif needs to be indented the same as the if.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ldap_add:Invalid Syntax Error (23) donanap Linux - General 3 09-07-2011 09:33 AM
[Python] Invalid Syntax - If statement LinuxCrayon Programming 4 12-07-2007 09:11 AM
python syntax error, what am I doing wrong? Tortanick Programming 1 04-03-2007 10:37 AM
LDAP Problem Invalid DN syntax (34) steve007 Linux - Newbie 3 10-18-2005 05:03 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM


All times are GMT -5. The time now is 03:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration