Qu

has_key

Builtin index · Collections & strings

result = has_key(d, key)

Input: d, key · Output: result

What it is

d is a Dict; key is a Str/number.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = has_key(d, key)
d Dictd is a Dict.
key Str or numberkey is a Str/number.
result bool
Returns a bool: whether the dict has that key, without reading it.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

d = dict(["a", "b"], [1, 2])
d = set(d, "c", 3)
print(get(d, "b"))       # 2

print(keys(d))           # ("a", "b", "c")

print(values(d))         # (1, 2, 3)

print(items(d))          # (("a", 1), ("b", 2), ("c", 3))

print(has_key(d, "c"))   # true

print(has_key(d, "z"))   # false

output
2
("a", "b", "c")
(1, 2, 3)
(("a", 1), ("b", 2), ("c", 3))
true
false

from collections-strings