Carvel Logo

Lists

#@ nums = [123, 374, 490]
first: #@ nums[0]

Copied here for convenience from Starlark specification.

x = []
x.append(1)  # None
x.append(2)  # None
x.append(3)  # None
x            # [1, 2, 3]
x = [1, 2, 3]
x.clear()  # None
x          # []
x = []
x.extend([1, 2, 3])  # None
x.extend(["foo"])    # None
x                    # [1, 2, 3, "foo"]
x = list("banana".codepoints())
x.index("a")      # 1 (bAnana)
x.index("a", 2)   # 3 (banAna)
x.index("a", -2)  # 5 (bananA)
x = ["b", "c", "e"]
x.insert(0, "a")   # None
x.insert(-1, "d")  # None
x                  # ["a", "b", "c", "d", "e"]
x = [1, 2, 3, 2]
x.remove(2)  # None (x == [1, 3, 2])
x.remove(2)  # None (x == [1, 3])
x.remove(2)  # error: element not found

(Help improve our docs: edit this page on GitHub)