pyspark.sql.functions.lit

pyspark.sql.functions.lit(col: Any) → pyspark.sql.column.Column[source]

Creates a Column of literal value.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn, str, int, float, bool or list, NumPy literals or ndarray.

the value to make it as a PySpark literal. If a column is passed, it returns the column as is.

Changed in version 3.4.0: Since 3.4.0, it supports the list type.

Returns
Column

the literal instance.

Examples

>>> df = spark.range(1)
>>> df.select(lit(5).alias('height'), df.id).show()
+------+---+
|height| id|
+------+---+
|     5|  0|
+------+---+

Create a literal from a list.

>>> spark.range(1).select(lit([1, 2, 3])).show()
+--------------+
|array(1, 2, 3)|
+--------------+
|     [1, 2, 3]|
+--------------+