Collections.UserString in Python

Collections.UserString in Python

Strings are the bytes that represent Unicode characters. Characters are strings that are of length one. The problem is that Python doesn’t support this data type character.

Example:

Output

String with the use of Single Quotes: 
JavaTpoint is the best platform to learn Python

 String with the use of Double Quotes: 
JavaTpoint is the best platform to learn Python

Collections.UserString

Python provides a String as a container, referred to as UserString, included in the collection module. This class functions as an additional class that wraps around string objects. This class is helpful in the case of creating strings of their own that have been modified or even with new features. It is an option to create new features to the string. This class can be used to take any argument that could be converted into strings and create a simulation of an unstructured string with its contents stored in a regular string. The string can be accessed via its data attribute.

Syntax:

The syntax for UserString is:

Example 1: (User dictionary with value and empty)

Output

UserString 1:  123546
UserString :  

Example 2: Mutable String (Append function and Remove function)

Output

The Original String:  JavaTpoint
String After Appending:  JavaTpointing
String after Removing:  JvTpointing

Conclusion

In this tutorial, we have discussed how to use UserString function of “collections” module in Python.


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263299.html

(0)
上一篇 2022年5月30日
下一篇 2022年5月30日

相关推荐

发表回复

登录后才能评论