polars.lit#

polars.lit(value: Any, dtype: Optional[type[polars.datatypes.DataType]] = None, allow_object: bool = False) Expr[source]#

Return an expression representing a literal value.

Parameters:
value

Value that should be used as a literal.

dtype

Optionally define a dtype.

allow_object

If type is unknown use an ‘object’ type. By default, we will raise a ValueException if the type is unknown.

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]))