On this page
  1. collections.UserString
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

collections.UserString

Prev: collections.UserList | Up: collections
Rel: collections.ChainMap, collections.Counter, collections.defaultdict, collections.deque
Ref: docs.python.org — collections.UserString
Tags: #public #python3 #stdlib #collections


Import

import collections
from collections import UserString

Signature & Overview

collections.UserString(seq)

collections.UserString class.

Methods & Attributes

Usage

from collections import UserString

class Slug(UserString):
    def __init__(self, seq) -> None:
        super().__init__(str(seq).strip().lower().replace(" ", "-"))

s = Slug("  Hello World ")
assert s == "hello-world" and isinstance(s.upper(), Slug)

Gotchas

REPL Inspect

from collections import UserString
help(UserString)

Linked from

Related notes