7

I am reading a Python book that uses the symbol

<-

It seems to be used interchangeably with the = sign. Is this a normal symbol to explain this? I have never seen it used elsewhere. enter image description here

CoderJK
  • 271
  • 2
  • 7
  • 1
    The difference of these assignment operators is actually a more [popular discussion in R](http://stackoverflow.com/questions/1741820/assignment-operators-in-r-and). Possibly, your citation referred to R and not Python? – Parfait Jul 18 '15 at 19:30
  • Definitely R syntax. – Malik Brahimi Jul 18 '15 at 19:36
  • 1
    I suppose it could be the `(*p).` C operator in a right-to-left language. But seriously, it is poor typesetting for the symbol `←` which I've seen used mostly in pseudo-code. It is pronounced "gets" as in "userAge gets 0". – msw Jul 18 '15 at 19:37
  • This isn't a question about Python at all -- it's a question about syntax and typography in the book you're reading, which *wasn't* following Python convention in that example. – Charles Duffy Jul 18 '15 at 19:42
  • Now that I know the answer, I absolutely agree it is no longer a Python question. – CoderJK Jul 19 '15 at 14:44

3 Answers3

7

It's not a symbol, it's simply showing that when you make an assignment using '=' you are placing the value on the right into the variable on the left.

Ajaypayne
  • 517
  • 3
  • 12
6

a <- b (better formatted as a < -b) means "a less than minus b" , so

>>> a = -5
>>> b = 3
>>> a <- b
True

>>> a = 3
>>> b = 4
>>> a <- b
False

In your image, as others have pointed out, the author is just indicating an assignment, it's unfortunate that the typography made it look like code, it wasn't meant to be a "less than minus".

Roshan Mathews
  • 5,788
  • 2
  • 26
  • 36
  • 3
    The only accurate answer. – Malik Brahimi Jul 18 '15 at 19:35
  • 2
    @MalikBrahimi, it's only accurate at answering a question that only came up by misreading the text; the text *clearly* did not in fact mean that `userAge <- 0` was valid Python syntax at all (though it is indeed so, that's strictly coincidental). – Charles Duffy Jul 18 '15 at 19:41
  • 1
    @Charles I wouldn't say "clearly", because, as Roshan Mathews points out, it was formatted as code, and could be confusing to the reader. – Nick Mertin Jul 18 '15 at 19:46
  • Granted, it's only clear when taking context into account; reading it out of context is, I'd argue, what prompted the OP to ask this question. – Charles Duffy Jul 18 '15 at 19:47
  • I'll have to use this in a code obfuscation challenge sometime – John La Rooy Jul 18 '15 at 23:01
4

It's just a pseudo-code example, not Python syntax.

melpomene
  • 84,125
  • 8
  • 85
  • 148
DeepSpace
  • 78,697
  • 11
  • 109
  • 154