Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit c0fd3fc

Browse files
minor wording fixes
1 parent e689dcf commit c0fd3fc

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

  • content/python/concepts/collections-module/terms/userstring

content/python/concepts/collections-module/terms/userstring/userstring.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
---
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.'
44
Subjects:
55
- 'Computer Science'
6+
- 'Data Science'
67
Tags:
7-
- 'Strings'
88
- 'Data Types'
9+
- 'Strings'
910
CatalogContent:
1011
- 'learn-python-3'
1112
- 'paths/computer-science'
1213
---
1314

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.
1516

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`.
1718
1819
## Syntax
1920

@@ -25,7 +26,7 @@ A `UserString` can be initialized either as a sequence of chars or a string. It
2526

2627
## Codebyte Example
2728

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:
2930

3031
```codebyte/python
3132
from collections import UserString
@@ -36,9 +37,9 @@ print(f"{customString.upper()}\n")
3637
print(f"Substring of the first word: {customString[0 : 7]}\n")
3738
3839
class NoVowels(UserString):
39-
def __init__(self, seq):
40-
# Remove vowels from the string
41-
super().__init__(''.join(ch for ch in seq if ch.lower() not in "aeiou"))
40+
def __init__(self, seq):
41+
# Remove vowels from the string
42+
super().__init__(''.join(ch for ch in seq if ch.lower() not in "aeiou"))
4243
4344
s = NoVowels("Hello World")
4445
print(f"Word without any vowels left: {s}")

0 commit comments

Comments
 (0)