str2d.Str2D.__add__

Str2D.__add__(other: Str2D | str, right_side=False) Str2D[source]

Adding one Str2D object to another or a string to a Str2D object is the main point of this class. We can add a Str2D object to another Str2D object in order to concatenate them horizontally. Both objects will be expanded to have the same height while respecting the alignment parameters. When adding a string to a Str2D object, the string will be wrapped in a Str2D object and treated as described above. In the case of adding another Str2D object, the expansion will use the expansion argument ‘mode’ set to ‘edge’. This allows the expansion to repeat the string intuitively to the edge of the Str2D object.

Parameters:
  • other (Union[Str2D, str]) – The Str2D object or string to add.

  • right_side (bool, optional) – If True, the Str2D object will be added to the right side of the other Str2D object, by default False.

Returns:

A new Str2D object with the added data.

Return type:

Str2D

See also

add

Add the data.

__add__

Add the data.

__radd__

Add the data.

add

Add the data.

Examples

Let’s create several instances of Str2D and assign them to the variables a, b, and c.

from str2d import Str2D

a = Str2D('a b c d\ne f g\nh i\nj')
b = Str2D('1 2 3\n4 5 6\n7 8 9')
c = Str2D('x y z\nu v w\nq r s')

We can add the data horizontally by using the Str2D objects with the + operator.

a + b + c
a b c d1 2 3x y z
e f g  4 5 6u v w
h i    7 8 9q r s
j

We can also add a string to the Str2D object.

a + ' hello ' + c
a b c d hello x y z
e f g   hello u v w
h i     hello q r s
j       hello

From the right side.

'hello ' + a
hello a b c d
hello e f g
hello h i
hello j