# Difference between Tuple and NTuple

**URL:** <https://discourse.julialang.org/t/difference-between-tuple-and-ntuple/107357>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 9, 2023, 1:16pm UTC](https://discourse.julialang.org/t/difference-between-tuple-and-ntuple/107357 "2023-12-09T13:16:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiang\_ming\_zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiang_ming_zhang/32/204063_2.png) [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Post date:** [December 9, 2023, 1:16pm UTC](https://discourse.julialang.org/t/difference-between-tuple-and-ntuple/107357/1 "2023-12-09T13:16:12Z")

</div>

Is ‘NTuple’ a more specific ‘Tuple’? It seems that in a Tuple, the elements can have different types, but in an NTuple, the elements must have the same type?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [December 9, 2023, 1:20pm UTC](https://discourse.julialang.org/t/difference-between-tuple-and-ntuple/107357/2 "2023-12-09T13:20:24Z")

</div>

By hitting the `?` key in the REPL, you can open the help mode which is really helpful for questions like this.

```julia-repl
help?> Tuple
search: Tuple tuple NTuple ntuple NamedTuple @NamedTuple isdispatchtuple UnitUpperTriangular

  Tuple{Types...}

  A tuple is a fixed-length container that can hold any values of different types, but cannot be modified (it is immutable). The values
  can be accessed via indexing. Tuple literals are written with commas and parentheses:

  julia> (1, 1+1)
  (1, 2)
  
  julia> (1,)
  (1,)
  
  julia> x = (0.0, "hello", 6*7)
  (0.0, "hello", 42)
  
  julia> x[2]
  "hello"
  
  julia> typeof(x)
  Tuple{Float64, String, Int64}

  A length-1 tuple must be written with a comma, (1,), since (1) would just be a parenthesized value. () represents the empty (length-0)
  tuple.

  A tuple can be constructed from an iterator by using a Tuple type as constructor:

  julia> Tuple(["a", 1])
  ("a", 1)
  
  julia> Tuple{String, Float64}(["a", 1])
  ("a", 1.0)

  Tuple types are covariant in their parameters: Tuple{Int} is a subtype of Tuple{Any}. Therefore Tuple{Any} is considered an abstract
  type, and tuple types are only concrete if their parameters are. Tuples do not have field names; fields are only accessed by index.
  Tuple types may have any number of parameters.

  See the manual section on Tuple Types.

  See also Vararg, NTuple, ntuple, tuple, NamedTuple.

```

```julia-repl
help?> NTuple
search: NTuple ntuple NamedTuple @NamedTuple UnitUpperTriangular

  NTuple{N, T}

  A compact way of representing the type for a tuple of length N where all elements are of type T.

  Examples
  ≡≡≡≡≡≡≡≡

  julia> isa((1, 2, 3, 4, 5, 6), NTuple{6, Int})
  true

  See also ntuple.

```

---

<div class="post-metadata">

**Author:** ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)\
**Post date:** [February 7, 2025, 2:14pm UTC](https://discourse.julialang.org/t/difference-between-tuple-and-ntuple/107357/3 "2025-02-07T14:14:21Z")

</div>

As it was still not totally clear to me, I tested it:

```julia
julia> Tuple{Int, Int} === NTuple{2, Int}
true

```

This already follows from the `isa` relationship together with no subtyping of concrete types, but for everyone else who did not see that initially:  
Both types are identical for homogeneous tuples.
