For questions regarding the `:=` operator available in several languages
Questions tagged [colon-equals]
60 questions
252
votes
6 answers
What does colon equal (:=) in Python mean?
What does the := operand mean, more specifically for Python?
Can someone explain how to read this snippet of code?
node := root, cost = 0
frontier := priority queue containing node only
explored := empty set

Julio
- 2,573
- 2
- 11
- 7
191
votes
7 answers
What's the difference between := and = in Makefile?
For variable assignment in Make, I see := and = operator. What's the difference between them?

prosseek
- 182,215
- 215
- 566
- 871
172
votes
2 answers
Assign multiple columns using := in data.table, by group
What is the best way to assign to multiple columns using data.table? For example:
f <- function(x) {c("hi", "hello")}
x <- data.table(id = 1:10)
I would like to do something like this (of course this syntax is incorrect):
x[ , (col1, col2) := f(),…

Alex
- 19,533
- 37
- 126
- 195
130
votes
4 answers
no new variables on left side of :=
What's happening here?
package main
import "fmt"
func main() {
myArray :=[...]int{12,14,26} ;
fmt.Println(myArray)
myArray :=[...]int{11,12,14} //error pointing on this line
fmt.Println(myArray) ;
}
It throws an…

Runes
- 1,411
- 2
- 9
- 5
129
votes
12 answers
What does ":=" do?
I've seen := used in several code samples, but never with an accompanying explanation. It's not exactly possible to google its use without knowing the proper name for it.
What does it do?

Cyclone
- 17,939
- 45
- 124
- 193
91
votes
1 answer
When should I use the := operator in data.table?
data.table objects now have a := operator. What makes this operator different from all other assignment operators? Also, what are its uses, how much faster is it, and when should it be avoided?

Ari B. Friedman
- 71,271
- 35
- 175
- 235
91
votes
1 answer
:= vs = in make macros
Possible Duplicate:
What is the difference between the GNU Makefile variable assignments =, ?=, := and +=?
I only know very basic makefile syntax, and was reading through another project's makefile and came across := for macro declaration. Why…

Aaron Yodaiken
- 19,163
- 32
- 103
- 184
65
votes
8 answers
What is the difference between := and = in Go?
I am new to Go programming language.
I noticed something strange in Go: I thought that it used := and substitutes = in Python, but when I use = in Go it is also works.
What is the difference between := and =?

whale_steward
- 2,088
- 2
- 25
- 37
57
votes
4 answers
What is the difference between = and := in Scala?
What is the difference between = and := in Scala?
I have googled extensively for "scala colon-equals", but was unable to find anything definitive.

Jay Taylor
- 13,185
- 11
- 60
- 85
51
votes
4 answers
The forgotten assignment operator "=" and the commonplace ":="
The documentation for PL/pgSQL says, that declaration and assignment to variables is done with :=.
But a simple, shorter and more modern (see footnote) = seems to work as expected:
CREATE OR REPLACE FUNCTION foo() RETURNS int AS $$
DECLARE
…

A.H.
- 63,967
- 15
- 92
- 126
51
votes
2 answers
Why has data.table defined := rather than overloading <-?
data.table has introduced the := operator. Why not overload <-?

Matt Dowle
- 58,872
- 22
- 166
- 224
44
votes
3 answers
var vs := in Go
In the Go web server example here: http://golang.org/doc/effective_go.html#web_server
The following line of code works
var addr = flag.String("addr", ":1718", "http service address")
but changing it to
addr := flag.String("addr", ":1718", "http…

Sudhir Jonathan
- 16,998
- 13
- 66
- 90
36
votes
2 answers
Bash script what is := for?
Does anyone know what is := for?
I tried googling but it seems google filters all symbol?
I know the below is something like checking if the variable HOME is a directory and then something is not equal to empty string.
if [ "${HOME:=}" != "" ] &&…

freshWoWer
- 61,969
- 10
- 36
- 35
34
votes
1 answer
What does the := operator mean in mysql?
I have a mysql table (scho_id,school_name,school_views).
I was looking for a mysql query to get rank of schools on the basis of school_views.
I found this solution on stackoverflow.
SET @points := -1, @num := 0;
SELECT scho_id
, school_views
,…

prograshid
- 876
- 3
- 12
- 32
29
votes
3 answers
What is the R assignment operator := for?
By digging into R source code (file R-3.2.2/src/main/gram.y lines 2836 to 2852) I found that the R parser/tokenizer considers that := is a LEFT_ASSIGNMENT token.
But when trying to use it as an assignment operator in R.3.2.2,
I have an error…

Romain Jacotin
- 311
- 1
- 3
- 6