pyspark.sql.functions.
lit
Creates a Column of literal value.
Column
New in version 1.3.0.
Changed in version 3.4.0: Supports Spark Connect.
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.
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]| +--------------+