Tuples in Julia are an immutable collection of distinct values of same or different datatypes separated by commas. Tuples are more like arrays in Julia except that arrays only take values of similar datatypes. The values of a tuple can not be changed because tuples are immutable. Tuples are a heterogeneous collection of values.
The sequence of values stored in a tuple can be of any type, and they are indexed by integers.
Values of a tuple are syntactically separated by ‘commas’. Although it is not necessary, it is more common to define a tuple by closing the sequence of values in parentheses. This helps in understanding the Julia tuples more easily.
Tuple_name = (value1, value2, value3, ...)
Accessing elements from a tuple
Elements of a tuple can be easily extracted with the use of square brackets(). Loops can also be used to extract more tha one element from a tuple. Also, a range of elements can also be extracted from a tuple by passing a range within square brackets just like strings.
Operations on Tuples
Tuples allow performing various operations on them as per user needs. These operations can be like reverse, length, map, isempty, etc.
- Julia end Keyword | Marking end of blocks in Julia
- Julia function keyword | Create user-defined functions in Julia
- Julia continue Keyword | Continue iterating to next value of a loop in Julia
- Julia break Keyword | Exiting from a loop in Julia
- Julia local Keyword | Creating a local variable in Julia
- Julia global Keyword | Creating a global variable in Julia
- Getting ceiling value of x in Julia - ceil() Method
- Getting floor value of x in Julia - floor() Method
- Getting the minimum value from a list in Julia - min() Method
- Package Management in Julia
- Visualisation in Julia
- Random Numbers Ecosystem in Julia - The Pseudo Side
- Accessing element at a specific index in Julia - getindex() Method
- Get size of string in Julia - sizeof() Method
- Reverse a string in Julia - reverse() Method
- Fill an array with specific values in Julia | Array fill() method
- Accessing each element of a collection in Julia - foreach() Method
- Counting number of elements in an array in Julia - count() Method
- Julia Language Introduction
- Checking for true values in an array in Julia - any() and all() Methods
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.