Python‎ > ‎str‎ > ‎

str.maketrans()


Definition
Return a translation table usable for str.translate().

Syntax
maketrans(x, y=None, z=None, /)

Parameters
x=string
y=string

Examples
 >>> x="abcd"
>>> y="fghi"
>>> z=x.maketrans(x,y)
>>> print(z)
{97: 102, 98: 103, 99: 104, 100: 105}


Returns are:
 >>> x="1234"
>>> y="5678"
>>> z=str.maketrans(x,y)
>>> z
{49: 53, 50: 54, 51: 55, 52: 56}
>>> 
>>> z.__eq__({49: 53, 50: 54, 51: 55, 52: 56})
True
>>> z.items()
dict_items([(49, 53), (50, 54), (51, 55), (52, 56)])
>>> z.values()
dict_values([53, 54, 55, 56])

Comments