Can't Assign to literal Error Message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bittuphilip
    New Member
    • Jul 2010
    • 1

    #1

    Can't Assign to literal Error Message

    Hi this is Bits here
    My Question is When i try to run my prog.it is giving an exception.

    i.e can't assign to Literal.Could you tell me why?

    the error msg is:
    Syntax Error :Can't Assign to literal


    the code is :
    Code:
    x=50,x=2
    def Funct(x):
        print'the values of x is:',x
    
    
        print 'Now the value of x is:',x
    
    
    
    Funct(x)
    print'The value of x is same as the First one :',x
    Last edited by bvdet; Jul 13 '10, 04:32 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    The interpreter is trying to assign a tuple to x.

    Do this instead:
    Code:
    x=50, 2
    or
    Code:
    x=50
    x=2
    Code:
    >>> x=5,x=2
    Traceback (SyntaxError: can't assign to literal
    >>> 
    >>> x=50,2
    >>> x
    (50, 2)
    >>>

    Comment

    Working...