-2

Simple question here. When assigning a variable why does the order have to be:

variable = 5
#and not
5 = variable

Is it because we can't assign values to variables? Does it have something to do with how a computer stores variables to memory? Or is it arbitrary? Just starting to learn to code so forgive the novice question.

petezurich
  • 6,779
  • 8
  • 29
  • 46
  • 2
    You cannot have variable starting with number in python. https://www.python.org/dev/peps/pep-0572/ – Debendra Feb 28 '20 at 04:01
  • 1
    Because you are setting the variable to equal 5, not 5 to equal to the variable. Because Python aims to read like human language, it is more natural to put it on the left. – iz_ Feb 28 '20 at 04:02
  • 2
    They had to pick one direction or the other when they were designing things. They picked this one. It's like driving on the left or the right. – user2357112 supports Monica Feb 28 '20 at 04:03
  • Voted to reopen, OPs question is about the directionality of assignment, not about the valid assignment target names – juanpa.arrivillaga Feb 28 '20 at 04:10

1 Answers1

3

It's arbitrary. Some languages have it the other way around, but they usually use a syntax like
5 -> variable or 5 → variable — languages that use = or := for assignment generally put the target of the assignment on the left.

hobbs
  • 187,508
  • 16
  • 182
  • 271