Vyper theorytheory 0/50 · 0%
Types · easy

17. Bytes and String types

Fixed-length Bytes[N] and String[N] with a max size.

Both `Bytes[N]` and `String[N]` carry a maximum length in their type — the actual stored value can be shorter, but never longer. This bound is what lets the compiler statically reason about memory and calldata costs.

name: public(String[64])
data: public(Bytes[256])

@external
def set_name(_name: String[64]):
    self.name = _name

Concatenation and slicing are supported via builtins like `concat()` and `slice()`, but every result must still fit within a declared maximum length.

Check your understanding

  1. 1. What does the N in String[N] represent?

  2. 2. Why must Bytes/String types declare a max length?

  3. 3. Which builtin joins two byte/string values?