Spark 基础 —— Range

until vs to

  • until:不包括右端点
  • to:包括右端点
scala> 0 until 5
res0: scala.collection.immutable.Range.Inclusive = Range(0, 1, 2, 3, 4)
scala> 0 to 5
res1: scala.collection.immutable.Range = Range(0, 1, 2, 3, 4, 5)

by:设置步长

也即默认步长为1

scala> 5 to 40 by 5
res2: scala.collection.immutable.Range.Inclusive = Range(5, 10, 15, 20, 25, 30, 35, 40)
scala> 5 until 40 by 5
res3: scala.collection.immutable.Range = Range(5, 10, 15, 20, 25, 30, 35)

你可能感兴趣的:(Spark 基础 —— Range)