Python error "Python: can't assign to literal"

1.0K    Asked by ElayneBalding in Python , Asked on Apr 18, 2021

I am trying to run this code in python. 

and getting syntax errors.

a = 2, b =4

But I am getting an error that says”python can't assign to literal”:

SyntaxError: can't assign to literal

How can I resolve this?

Answered by Elayne Balding

This is a simple syntax error. In python you cannot assign values to variables like this. I think the syntax you are looking for is this:

a, b = 2, 4
Or you can also do it like this:
a = 2
b = 4

Your Answer

Interviews

Parent Categories