12

Really basic syntax question in pseudocode. What does := mean in Pseudocode?
Example

a := 1
moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
ElectronAnt
  • 2,115
  • 7
  • 22
  • 39

4 Answers4

29

Pseudocode examples on Wikipedia usually use := as the assignment operator, like Pascal does (I haven't found any counterexamples yet).

You can't use it in Python directly as it would be a SyntaxError:

>>> a := 1
  File "<stdin>", line 1
    a := 1
      ^
SyntaxError: invalid syntax

Use

a = 1

instead.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
  • The question could get deleted though..... You might lose the rep but I think you'll keep the badge! ;-) – David Heffernan Apr 21 '12 at 21:59
  • @DavidHeffernan: I think if that happens I do get to keep the badge, but I don't get another one when my next answer reaches 10 upvotes... – Tim Pietzcker Apr 21 '12 at 22:12
  • 1
    I hate to star negatively-voted questions, but I just had to do this after seeing your answer. – BoltClock Apr 22 '12 at 12:13
  • Wow, we even have a Programmers counterpart: http://programmers.stackexchange.com/questions/101716/in-pseudo-code-what-does-mean – BoltClock Apr 22 '12 at 12:19
  • @BoltClock'saUnicorn: You should look through the revision history of the question to see what it started out as. In its current state it isn't such a bad question any more IMO, but it was quite funny at the start. – Tim Pietzcker Apr 22 '12 at 16:21
11

In pseudo code := means assignment whereas = means equality

a:=1 in pseudo code means a=1 in most languages while, a=1 is generally used for conditional checking in pseudo code i.e. if(a=1) in pseudocode means if (a==1) in most languages.

gopi1410
  • 6,567
  • 9
  • 41
  • 75
4

If you are talking about translating from another language, the := operator is used in pascal like languages for assigning variables.

In python the equivalent would just be =.

Pascal:

a := 1

Python:

a = 1
Slipstream
  • 385
  • 3
  • 10
2

Pascal:

a := 1

Python:

a = 1

:)

McGarnagle
  • 101,349
  • 31
  • 229
  • 260