By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,609 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,609 IT Pros & Developers. It's quick & easy.

can't assign to a literal error shows up

P: 1
cant assign to a literal error shows up. what am i doing wrong here please
Expand|Select|Wrap|Line Numbers
  1. varA=5, varB='a'
  2. if type(varA) == str or type(varB) == str:
  3.     print('string involved')
  4. elif varA > varB:
  5.     print('bigger')
  6. elif varA == varB:
  7.     print('equal')
  8. else:
  9.     # If none of the above conditions are true,
  10.     # it must be the case that varA < varB
  11.     print('smaller')
Feb 13 '13 #1
Share this Question
Share on Google+
1 Reply

bvdet
Expert Mod 2.5K+
P: 2,851
You cannot make assignments on one line separated by a comma.
Expand|Select|Wrap|Line Numbers
  1. >>> varA=5,varB=6
  2. Traceback (  File "<interactive input>", line 1
  3. SyntaxError: can't assign to literal
  4. >>> varA=5
  5. >>> 
You could do it like this:
Expand|Select|Wrap|Line Numbers
  1. >>> varA, varB = 5, 'a'
  2. >>> varA
  3. 5
  4. >>> varB
  5. 'a'
  6. >>> 
Feb 13 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.