What does ":=" mean in Pseudocode? [closed]
Asked Answered
T

4

13

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

a := 1
Tinct answered 21/4, 2012 at 21:39 Comment(11)
I just want to know what ":=" operator does and how it is different from just "="Tinct
What is it translating from?Lucerne
@Aneem Try using it. What happens? It is not valid in Python, but some other languages use := for the assignment operator.Killer
That's a Pascal assignment. Did you get the wrong language. Show some more code.Gatewood
sorry! it's not python, it was using coding from this page: en.wikipedia.org/wiki/Modular_exponentiationTinct
Can we delete this post? It is misleading, once again, very sorry.Tinct
Instead of deleting, why not just change your question to be about pseudocode instead of Python? I will remove my downvote, for oneQuindecennial
It's that well known language, pseudocodeGatewood
Haha @DavidHeffernan, what I mean is that pseudocode does have a StackOverflow tag.Quindecennial
Voting to close as i doubt this question will have value to anyone in the future. I was going to remove the Python tag, except it specifically says Python on the title.Tjon
See - programmers.stackexchange.com/questions/101716/…Questionable
E
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.

Elayneelazaro answered 21/4, 2012 at 21:42 Comment(5)
The question could get deleted though..... You might lose the rep but I think you'll keep the badge! ;-)Gatewood
@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...Elayneelazaro
I hate to star negatively-voted questions, but I just had to do this after seeing your answer.Fields
Wow, we even have a Programmers counterpart: programmers.stackexchange.com/questions/101716/…Fields
@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.Elayneelazaro
O
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.

Overburden answered 21/4, 2012 at 21:53 Comment(0)
A
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
Allot answered 21/4, 2012 at 21:44 Comment(0)
S
2

Pascal:

a := 1

Python:

a = 1

:)

Saeger answered 21/4, 2012 at 22:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.