Creating a custom string type in Python

In Python, it is possible to create your own string class, which you can create by typing something like:

a = b"some string"
a.someCustomMethod()

Just like python has strings u""and r""?

+4
source share
1 answer

Just write your own string class, but you cannot get the syntax of the construct you want. The closest you can get is

a = MyString("some string")

where MyStringis your own class. I suppose you can make an alias b = MyStringif you want.

, , b"some string" bytestring. Python 2 . Python 3 bytes, unicode Python 3.

+6

Source: https://habr.com/ru/post/1523281/


All Articles