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

str

Prev: staticmethod | Up: __builtins__ | Next: sum
Rel: bool, int, float, complex, bytes
Ref: docs.python.org — str
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import str

Overview & Signature

str(object='') -> str

str(bytes_or_buffer[, encoding[, errors]]) -> str Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer

Common Methods & Attributes

Usage

s = "  hello, world  "
assert s.strip().split(", ") == ["hello", "world"]
assert "prefix_name".removeprefix("prefix_") == "name"

Gotchas

REPL Inspect

help(str)

Linked from

Related notes