# Comparing tuples with and without parentheses

**URL:** <https://discourse.julialang.org/t/comparing-tuples-with-and-without-parentheses/53440>\
**Category:** New to Julia\
**Tags:** testing, tuple\
**Created:** [January 16, 2021, 6:27pm UTC](https://discourse.julialang.org/t/comparing-tuples-with-and-without-parentheses/53440 "2021-01-16T18:27:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![schneiderfelipe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schneiderfelipe/32/18004_2.png) [@schneiderfelipe](https://discourse.julialang.org/u/schneiderfelipe)\
**Post date:** [January 16, 2021, 6:27pm UTC](https://discourse.julialang.org/t/comparing-tuples-with-and-without-parentheses/53440/1 "2021-01-16T18:27:55Z")

</div>

I’m a bit confused about the rules concerning tuples, parentheses, commas, and how Julia interprets them.

Could someone explain to me the following behavior?

```julia
julia> (1.0, 2.0) == (1.0, 2.0) # Nice
true

julia> (1.0, 2.0) .== (1.0, 2.0) # Charming 🤩
(true, true)

# Surprising perhaps:
julia> (1.0, 2.0) == 1.0, 2.0 # I get it, stuck at the comma
(false, 2.0)

julia> (1.0, 2.0) .== 1.0, 2.0 # Sum of the last previous, fine
((true, false), 2.0)

# I am completely lost in those two:
julia> 1.0, 2.0 == 1.0, 2.0 # WTF?
(1.0, false, 2.0)

julia> 1.0, 2.0 .== 1.0, 2.0 # Same?
(1.0, false, 2.0)

```

There are places where Julia is more pedantic than, e.g., Python when it comes to parentheses, and this seems to be the case. I’m used to assignments like

```julia
julia> a, b = 1, 2
(1, 2)

julia> a
1

julia> b
2

```

It is OK to use `(...)` in `for` loops like (Python won’t require them),

```julia
julia> for (i, a) in enumerate("confused by tuples")
           println("$i: $a")
       end
1: c
2: o
3: n
4: f
5: u
6: s
7: e
8: d
9:  
10: b
11: y
12:  
13: t
14: u
15: p
16: l
17: e
18: s

```

But the examples on tuple comparison above confuses me a bit. Julia’s parser seems a bit “greedier” than Python’s, if that makes sense. What are the exact rules concerning tuples, parentheses, commas, etc.?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 16, 2021, 6:33pm UTC](https://discourse.julialang.org/t/comparing-tuples-with-and-without-parentheses/53440/2 "2021-01-16T18:33:23Z")

</div>

`1.0, 2.0 == 1.0, 2.0`: this makes perfect sense when you look at the commas. These create a tuple of three values.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 16, 2021, 6:59pm UTC](https://discourse.julialang.org/t/comparing-tuples-with-and-without-parentheses/53440/3 "2021-01-16T18:59:08Z")

</div>

> [@schneiderfelipe](#):
>
> What are the exact rules concerning tuples, parentheses, commas, etc.?

Commas have lower precedence than all operators except for assignment (`=`, `+=`, etc).

> [@schneiderfelipe](#):
>
> Julia’s parser seems a bit “greedier” than Python’s

As far as I can tell, the precedence of tuple construction in Python is basically the same?

```py
>>> (1.0, 2.0) == (1.0, 2.0)
True
>>> (1.0, 2.0) == 1.0, 2.0
(False, 2.0)
>>> 1.0, 2.0 == 1.0, 2.0
(1.0, False, 2.0)

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [January 17, 2021, 1:29am UTC](https://discourse.julialang.org/t/comparing-tuples-with-and-without-parentheses/53440/4 "2021-01-17T01:29:21Z")

</div>

> [@schneiderfelipe](#):
>
> Julia’s parser seems a bit “greedier” than Python’s, if that makes sense.

[That’s probably](https://julialang.org/blog/2012/02/why-we-created-julia/)

> because we are greedy

(just joking)

---

<div class="post-metadata">

**Author:** ![schneiderfelipe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schneiderfelipe/32/18004_2.png) [@schneiderfelipe](https://discourse.julialang.org/u/schneiderfelipe)\
**Post date:** [January 17, 2021, 1:41pm UTC](https://discourse.julialang.org/t/comparing-tuples-with-and-without-parentheses/53440/5 "2021-01-17T13:41:56Z")

</div>

Now I get it! Thank you all for the clarifications. I mixed up comparison and assignment syntaxes which by the way are the same as in Python, as @stevengj pointed out.
