|
@@ -514,6 +514,20 @@ assign to it::
|
|
d[4] = "hello" # Add integer 4 as a key and assign the String "hello" as its value.
|
|
d[4] = "hello" # Add integer 4 as a key and assign the String "hello" as its value.
|
|
d["Godot"] = 3.01 # Add String "Godot" as a key and assign the value 3.01 to it.
|
|
d["Godot"] = 3.01 # Add String "Godot" as a key and assign the value 3.01 to it.
|
|
|
|
|
|
|
|
+ var test = 4
|
|
|
|
+ # Prints "hello" by indexing the dictionary with a dynamic key.
|
|
|
|
+ # This is not the same as `d.test`. The bracket syntax equivalent to
|
|
|
|
+ # `d.test` is `d["test"]`.
|
|
|
|
+ print(d[test])
|
|
|
|
+
|
|
|
|
+.. note::
|
|
|
|
+
|
|
|
|
+ The bracket syntax can be used to access properties of any
|
|
|
|
+ :ref:`class_Object`, not just Dictionaries. Keep in mind it will cause a
|
|
|
|
+ script error when attempting to index a non-existing property. To avoid
|
|
|
|
+ this, use the :ref:`Object.get() <class_Object_method_get>` and
|
|
|
|
+ :ref:`Object.set() <class_Object_method_set>` methods instead.
|
|
|
|
+
|
|
Data
|
|
Data
|
|
----
|
|
----
|
|
|
|
|