Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

03 D 18 H : 23 M : 51 S   Apply Now

Scala

You are currently auditing this course.
45 / 53

Scala - Assessment - Declare a Tuple

A tuple in Scala is an immutable collection to hold objects of different types.

A tuple is simply declared by putting the items inside () and its items are accessed via suffixes like ._1, _2 and so on. For example;

var tuple_new = ("1","World")
//or
var tuple_new = Tuple2("1","World")
//or
var tuple_new = new Tuple2("1","World")

//get the elements
var first_element = tuple_new._1
var second_element = tuple_new._2

Now, let's declare a tuple named myTuple, having below items.

  • 5
  • "Hello"
  • 100
INSTRUCTIONS
  • Switch to Jupyter tab.

  • Declare the tuple variable with the required name and items in Jupyter.

  • Press Shift+Enter.

  • Submit your answer.


Please login to comment

0 Comments

There are 14 new comments.