Remove leading and/or trailing whitespace from character strings.
Parameters
Name
Type
Description
Default
x
Union[str, List[str]]
a str, a list or an list-like object with text
required
which
str
either ‘both’, ‘left’ or ‘right’ indicating which side of x to trim
'both'
whitespace
str
a str with the whitespace characters to trim. Defaults to spact, tab, new line, carriage return
' \t\n\r'
Returns
Name
Type
Description
Union[str, List[str]]
a list of the same length as x or a str with whitespace removed
Examples
>>>from rlike import*>>> x =' Hello world '>>> trimws(x)'Hello world'>>> x = [' Hello world ', ' ABCDEF']>>> trimws(x, which ='left')['Hello world ', 'ABCDEF']>>> trimws(x, which ='right')[' Hello world', ' ABCDEF']