---
title: format_string
description: "format\\_string function in PySpark: Formats the arguments in printf-style and returns the result as a string column."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/functions/format_string
---

# format\_string

Formats the arguments in printf-style and returns the result as a string column.

For the corresponding Databricks SQL function, see [`format_string` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/format_string.md).

## Syntax

```python
from pyspark.sql import functions as dbf

dbf.format_string(format=<format>, *cols=<*cols>)
```

## Parameters

| Parameter | Type                          | Description                                                                    |
| --------- | ----------------------------- | ------------------------------------------------------------------------------ |
| `format`  | `literal string`              | string that can contain embedded format tags and used as result column's value |
| `cols`    | `pyspark.sql.Column` or `str` | column names or `~pyspark.sql.Column`\s to be used in formatting               |

## Returns

`pyspark.sql.Column`: the column of formatted results.

## Examples

```python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(5, "hello")], ["a", "b"])
df.select("*", dbf.format_string('%d %s', "a", df.b)).show()
```
