---
title: range (SparkSession)
description: "SparkSession.range method in PySpark: Creates a DataFrame with a single LongType column named id, containing elements in a range from start to end (exclusive) with step value step."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/sparksession/range
---

# range (SparkSession)

Creates a `DataFrame` with a single `LongType` column named `id`, containing elements in a range from `start` to `end` (exclusive) with step value `step`.

## Syntax

```
range(start, end=None, step=1, numPartitions=None)
```

## Parameters

| Parameter       | Type          | Description                                                                                        |
| --------------- | ------------- | -------------------------------------------------------------------------------------------------- |
| `start`         | int           | The start value.                                                                                   |
| `end`           | int, optional | The end value (exclusive). If omitted, `start` is used as the end value and the range begins at 0. |
| `step`          | int, optional | The incremental step (default: `1`).                                                               |
| `numPartitions` | int, optional | The number of partitions of the `DataFrame`.                                                       |

## Returns

`DataFrame`

## Examples

```python
spark.range(1, 7, 2).show()
# +---+
# | id|
# +---+
# |  1|
# |  3|
# |  5|
# +---+

# If only one argument is specified, it is used as the end value.
spark.range(3).show()
# +---+
# | id|
# +---+
# |  0|
# |  1|
# |  2|
# +---+
```
