You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 27, 2026. It is now read-only.
Copy file name to clipboardExpand all lines: content/python/concepts/collections-module/terms/userstring/userstring.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,20 @@
1
1
---
2
-
Title: 'collections.UserString'
3
-
Description: 'A custom wrapper for string objects.'
2
+
Title: 'UserString'
3
+
Description: 'A wrapper class for string objects that makes subclassing easier.'
4
4
Subjects:
5
5
- 'Computer Science'
6
+
- 'Data Science'
6
7
Tags:
7
-
- 'Strings'
8
8
- 'Data Types'
9
+
- 'Strings'
9
10
CatalogContent:
10
11
- 'learn-python-3'
11
12
- 'paths/computer-science'
12
13
---
13
14
14
-
A `UserString` is a class in the `collections` module. It is a custom wrapper for string objects, behaving like a string but allowing easier subclassing. Unlike directly subclassing [`str`](<(https://www.codecademy.com/resources/docs/python/dictionaries)>), `UserString` stores its content in the `.data` attribute. The seq parameter passed at initialization can be anything that can be converted into a `str`.
15
+
A **`UserString`** is a class in the `collections` module. It is a custom wrapper for string objects, behaving like a string but allowing easier subclassing. Unlike directly subclassing `str`, `UserString` stores its content in the `.data` attribute. The `seq` parameter passed at initialization can be any object that can be converted into a string.
15
16
16
-
**Note:**A`UserString`is a wrapper class that behaves like a sequence. The actual string is stored in the `.data` attribute.
17
+
> **Note:**While`UserString`behaves like a string and supports the same operations, some methods return a regular `str` instead of another `UserString`.
17
18
18
19
## Syntax
19
20
@@ -25,7 +26,7 @@ A `UserString` can be initialized either as a sequence of chars or a string. It
25
26
26
27
## Codebyte Example
27
28
28
-
The following example creates a `UserString`from an iterable (a string) and outputs various characteristics of the `UserString`:
29
+
The following example creates a `UserString`and demonstrates its usage, along with a subclass that removes vowels:
0 commit comments