pyspark.sql.functions.char_length#

pyspark.sql.functions.char_length(str)[source]#

Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.

New in version 3.5.0.

Parameters
strColumn or str

Input column or strings.

Examples

>>> import pyspark.sql.functions as sf
>>> spark.range(1).select(sf.char_length(sf.lit("SparkSQL"))).show()
+---------------------+
|char_length(SparkSQL)|
+---------------------+
|                    8|
+---------------------+