Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

einhan

  • 3 years ago

What does 'can't assign to literal' error mean? I did: '3 + 3' = 'six' print ('3 + 3') It gives me that error. I intended to get 'six' printed out, since I intended to assign 'six' to '3 + 3'

  • This Question is Closed
  1. Shadowys
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you cannot assign a string to another string '3+3' is an illegal name because there's numbers and operators only

  2. ParthKohli
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ``` var x = "y" ``` The above is the standard format for assignment.

  3. ParthKohli
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Note that it is not this: ``` var "x" = "y" ```

  4. MicroBot
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    on the left side u have to have a variable name to assign to a string ,a number,or an other variable that has to be on the right side. so if u wanted to call your variable something like 3+3 it cant be a string ,and u cant start the variable name with a number or have an operator in it. Instead you could call it threeplusthree or threeplus3. so: threeplus3='six' should do it. :) Check this for further info: (1.6.1. Literals and Identifiers) http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/variables.html

  5. shawnf
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you are trying to assign a value to another value you can only assign a value to a variable

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy