polars.lit

polars.lit(value: Optional[Union[float, int, str, datetime.date, datetime.datetime, polars.internals.series.Series, numpy.ndarray, Any]], dtype: Optional[Type[polars.datatypes.DataType]] = None) polars.internals.expr.Expr

A literal value.

Parameters
value

Value that should be used as a literal.

dtype

Optionally define a dtype.

Examples

Literal integer:

>>> pl.lit(1)  

Literal str:

>>> pl.lit("foo")  

Literal datetime:

>>> from datetime import datetime
>>> pl.lit(datetime(2021, 1, 20))  

Literal Null:

>>> pl.lit(None)  

Literal eager Series:

>>> pl.lit(pl.Series("a", [1, 2, 3]))