From d0782b18530c1c3767764129e60b47a81696b163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E5=9C=B0=20=E5=B8=8C=E7=95=99=E8=80=B6?= <65301509+KiruyaMomochi@users.noreply.github.com> Date: Sat, 25 Mar 2023 22:26:57 +0800 Subject: [PATCH] Document behaviour of dictionary.insert() when key exists (#282) --- docs/src/reference/types.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/src/reference/types.md b/docs/src/reference/types.md index aabe88510..59333eb89 100644 --- a/docs/src/reference/types.md +++ b/docs/src/reference/types.md @@ -663,6 +663,7 @@ instead of integers. You can access and create dictionary entries with the [field access notation]($scripting/#fields) (`.key`) to access the value. Dictionaries can be added with the `+` operator and [joined together]($scripting/#blocks). +To check whether a key is present in the dictionary, use the `in` keyword. You can iterate over the pairs in a dictionary using a [for loop]($scripting/#loops). @@ -686,6 +687,7 @@ special `(:)` syntax to create an empty dictionary. #dict.values() \ #dict.at("born") \ #dict.insert("city", "Berlin ") +#("name" in dict) ``` ## Methods @@ -706,6 +708,7 @@ Fails with an error if the key is not part of the dictionary. ### insert() Insert a new pair into the dictionary and return the value. +If the dictionary already contains this key, the value is updated. - key: string (positional, required) The key of the pair that should be inserted.