API Reference
tuple

def tuple(iterable: Iterable[Any] = (), /) -> TupleObject

Creates a persistent, immutable sequence object that behaves like Python's built-in tuple.

Familiar API: This class is designed as a persistent counterpart to Python's built-in collection. It implements the same interface and supports all standard operations, allowing you to use it easily as a drop-in replacement while providing automatic persistance.

Parameters

  • iterable Iterable[Any], default ()
    Optional iterable (list, tuple, generator) to initialize the tuple's elements. If not provided, an empty dbzero.tuple is created.

Returns

A new dbzero.tuple object.


Examples

Basic creation and usage

You can create a dbzero.tuple from any Python iterable. If you call it with no arguments, you get an empty tuple.

# Create an empty tuple
empty_tuple = db0.tuple()
print(len(empty_tuple))
# Expected output: 0
 
# Create a tuple from a list
# It can store various data types, including bytes
my_tuple = db0.tuple([1, "hello", b"world", True])
print(my_tuple[1])
# Expected output: "hello"
 
# Create from a generator expression
gen_tuple = db0.tuple(i for i in range(3))
print(gen_tuple == (0, 1, 2))
# Expected output: True

Standard tuple operations

A dbzero.tuple behaves just like a regular Python tuple. You can iterate over it, unpack it, and use its methods.

data_tuple = db0.tuple(['apple', 'banana', 'cherry', 'banana'])
 
# Unpacking
a, b, c, d = data_tuple
print(b)
# Expected output: 'banana'
 
# Methods: count() and index()
print(f"Count of 'banana': {data_tuple.count('banana')}")
# Expected output: Count of 'banana': 2
 
print(f"Index of 'cherry': {data_tuple.index('cherry')}")
# Expected output: Index of 'cherry': 2
 
# Comparison with a standard Python tuple
assert data_tuple == ('apple', 'banana', 'cherry', 'banana')