---
title: substr (Column)
description: "Column.substr method in PySpark: Return a substring of the column."
canonical_url: https://docs.databricks.com/gcp/en/pyspark/reference/classes/column/substr
---

# substr (Column)

Return a substring of the column.

## Syntax

```python
substr(startPos, length)
```

## Parameters

| Parameter  | Type          | Description                 |
| ---------- | ------------- | --------------------------- |
| `startPos` | int or Column | Starting position (1-based) |
| `length`   | int or Column | Length of the substring     |

## Returns

Column

## Examples

Example 1: Using integers for the input arguments.

```python
df = spark.createDataFrame(
     [(2, "Alice"), (5, "Bob")], ["age", "name"])
df.select(df.name.substr(1, 3).alias("col")).collect()
```

```Output
# [Row(col='Ali'), Row(col='Bob')]
```

Example 2: Using columns for the input arguments.

```python
df = spark.createDataFrame(
     [(3, 4, "Alice"), (2, 3, "Bob")], ["sidx", "length", "name"])
df.select(df.name.substr(df.sidx, df.length).alias("col")).collect()
```

```Output
# [Row(col='ice'), Row(col='ob')]
```
