Skip to main content

Documentation Index

Fetch the complete documentation index at: https://edgepython.com/llms.txt

Use this file to discover all available pages before exploring further.

Edge Python has no user-defined classes, but strings, lists, and dicts come with a curated set of built-in methods. They behave like CPython equivalents.
# Methods are accessed with dot notation
print("hello".upper())
print([3, 1, 2].count(1))
print({"a": 1}.get("a"))
Output
HELLO
1
1

String methods

Case transforms

print("hello".upper())
print("HELLO".lower())
print("hello world".capitalize())
print("hello world".title())
Output
HELLO
hello
Hello world
Hello World

Whitespace

print("  hi  ".strip())
print("  hi  ".lstrip())
print("  hi  ".rstrip())

# With a custom strip set
print("xxhelloxx".strip("x"))
Output
hi
hi  
  hi
hello

Predicates

print("123".isdigit())
print("abc".isdigit())

print("abc".isalpha())
print("abc123".isalpha())

print("abc123".isalnum())
print("abc 123".isalnum())
Output
True
False
True
False
True
False

Search and count

print("hello".startswith("he"))
print("hello".endswith("lo"))
print("hello".find("ll"))
print("hello".find("z"))
print("hello".count("l"))
Output
True
True
2
-1
2

Split, join, replace

print("a,b,c".split(","))
print("hello world".split()) # any whitespace
print(",".join(["a", "b", "c"]))
print("hello".replace("l", "L"))
Output
['a', 'b', 'c']
['hello', 'world']
a,b,c
heLLo

Padding

print("abc".center(7, "-"))
print("42".zfill(5))
print("-42".zfill(5))
Output
--abc--
00042
-0042

List methods

Pure (return a new value or query)

xs = [1, 2, 3, 2]

print(xs.index(2))
print(xs.count(2))

ys = xs.copy()
ys.append(99)
print(xs) # original unchanged
print(ys)
Output
1
2
[1, 2, 3, 2]
[1, 2, 3, 2, 99]

Mutating

These return None and modify the list in place.
xs = [1, 2, 3]

xs.append(4)
print(xs)

xs.extend([5, 6])
print(xs)

xs.insert(0, 99)
print(xs)
Output
[1, 2, 3, 4]
[1, 2, 3, 4, 5, 6]
[99, 1, 2, 3, 4, 5, 6]
xs = [1, 2, 3, 2]

xs.remove(2) # first occurrence
print(xs)

popped = xs.pop() # last
print(popped, xs)

popped = xs.pop(0) # by index
print(popped, xs)
Output
[1, 3, 2]
2 [1, 3]
1 [3]
xs = [3, 1, 4, 1, 5]
xs.sort()
print(xs)

xs.reverse()
print(xs)

xs.clear()
print(xs)
Output
[1, 1, 3, 4, 5]
[5, 4, 3, 1, 1]
[]

Dict methods

Views

d = {"a": 1, "b": 2, "c": 3}

print(list(d.keys()))
print(list(d.values()))
print(list(d.items()))
Output
['a', 'b', 'c']
[1, 2, 3]
[('a', 1), ('b', 2), ('c', 3)]

Lookup with default

d = {"a": 1}

print(d.get("a"))
print(d.get("z"))
print(d.get("z", 0))
Output
1
None
0

Mutation

d = {"a": 1}

d.update({"b": 2, "a": 99})
print(d)

removed = d.pop("a")
print(removed, d)

print(d.pop("missing", "fallback"))
Output
{'a': 99, 'b': 2}
99 {'b': 2}
fallback
d = {}
d.setdefault("a", 1)
d.setdefault("a", 999) # second call ignored
print(d)
Output
{'a': 1}

Method summary

String — str

MethodArityReturns
upper0uppercased copy
lower0lowercased copy
capitalize0first letter upper, rest lower
title0each word capitalized
strip0no leading/trailing whitespace
lstrip0 or 1left-strip; optional set of chars
rstrip0 or 1right-strip; optional set of chars
isdigit0bool: all ASCII digits
isalpha0bool: all alphabetic
isalnum0bool: all alphanumeric
startswith1bool
endswith1bool
find1index or -1
count1non-overlapping occurrences
split0 or 1list of pieces
join1joined string
replace2new string with all replacements
center1 or 2padded copy
zfill1zero-padded copy, sign-aware

List — list

MethodArityMutates?Returns
index1nofirst matching index
count1nomatching count
copy0noshallow copy
append1yesNone
extend1yesNone
insert2yesNone
remove1yesNone
pop0 or 1yespopped value
sort0yesNone
reverse0yesNone
clear0yesNone

Dict — dict

MethodArityMutates?Returns
keys0nolist of keys
values0nolist of values
items0nolist of (k, v) tuples
get1 or 2novalue or default
update1yesNone
pop1 or 2yespopped value or default
setdefault1 or 2yesexisting or default value