diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-06-15 09:30:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 09:30:23 +0200 |
commit | 0d1706c0575b129fa210a4b34f91dfff4d6af843 (patch) | |
tree | 305d79d33325c01ca9db738105411247b9c64f4a /doc | |
parent | 152bb86141b1427524df73f9ed3f273a4b76bb8f (diff) | |
parent | 7f01f68226c3aa32a372afba3b254402a9448830 (diff) |
Merge pull request #39462 from Calinou/doc-in-operator
Document the `in` operator in String, Array and Dictionary classes
Diffstat (limited to 'doc')
-rw-r--r-- | doc/classes/Array.xml | 10 | ||||
-rw-r--r-- | doc/classes/Dictionary.xml | 7 | ||||
-rw-r--r-- | doc/classes/Object.xml | 1 | ||||
-rw-r--r-- | doc/classes/String.xml | 14 |
4 files changed, 26 insertions, 6 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 7593f7dff4..9a3eccd8dc 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -200,7 +200,7 @@ <argument index="1" name="from" type="int" default="0"> </argument> <description> - Searches the array for a value and returns its index or -1 if not found. Optionally, the initial search index can be passed. + Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. </description> </method> <method name="find_last"> @@ -209,7 +209,7 @@ <argument index="0" name="value" type="Variant"> </argument> <description> - Searches the array in reverse order for a value and returns its index or -1 if not found. + Searches the array in reverse order for a value and returns its index or [code]-1[/code] if not found. </description> </method> <method name="front"> @@ -232,6 +232,12 @@ ["inside", 7].has(7) == true ["inside", 7].has("7") == false [/codeblock] + [b]Note:[/b] This is equivalent to using the [code]in[/code] operator as follows: + [codeblock] + # Will evaluate to `true`. + if 2 in [2, 4, 6, 8]: + pass + [/codeblock] </description> </method> <method name="hash"> diff --git a/doc/classes/Dictionary.xml b/doc/classes/Dictionary.xml index 4538e5ea4e..5413fa33c6 100644 --- a/doc/classes/Dictionary.xml +++ b/doc/classes/Dictionary.xml @@ -126,6 +126,13 @@ </argument> <description> Returns [code]true[/code] if the dictionary has a given key. + [b]Note:[/b] This is equivalent to using the [code]in[/code] operator as follows: + [codeblock] + # Will evaluate to `true`. + if "godot" in {"godot": "engine"}: + pass + [/codeblock] + This method (like the [code]in[/code] operator) will evaluate to [code]true[/code] as long as the key exists, even if the associated value is [code]null[/code]. </description> </method> <method name="has_all"> diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml index 87bcab25db..8d08688b41 100644 --- a/doc/classes/Object.xml +++ b/doc/classes/Object.xml @@ -15,6 +15,7 @@ print("position" in n) # Prints "True". print("other_property" in n) # Prints "False". [/codeblock] + The [code]in[/code] operator will evaluate to [code]true[/code] as long as the key exists, even if the value is [code]null[/code]. Objects also receive notifications. Notifications are a simple way to notify the object about different events, so they can all be handled together. See [method _notification]. </description> <tutorials> diff --git a/doc/classes/String.xml b/doc/classes/String.xml index 0dd6923129..24d92b822a 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -412,7 +412,13 @@ <argument index="1" name="from" type="int" default="0"> </argument> <description> - Finds the first occurrence of a substring. Returns the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed. + Finds the first occurrence of a substring. Returns the starting position of the substring or [code]-1[/code] if not found. Optionally, the initial search index can be passed. + [b]Note:[/b] If you just want to know whether a string contains a substring, use the [code]in[/code] operator as follows: + [codeblock] + # Will evaluate to `false`. + if "i" in "team": + pass + [/codeblock] </description> </method> <method name="find_last"> @@ -421,7 +427,7 @@ <argument index="0" name="what" type="String"> </argument> <description> - Finds the last occurrence of a substring. Returns the starting position of the substring or -1 if not found. + Finds the last occurrence of a substring. Returns the starting position of the substring or [code]-1[/code] if not found. </description> </method> <method name="findn"> @@ -432,7 +438,7 @@ <argument index="1" name="from" type="int" default="0"> </argument> <description> - Finds the first occurrence of a substring, ignoring case. Returns the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed. + Finds the first occurrence of a substring, ignoring case. Returns the starting position of the substring or [code]-1[/code] if not found. Optionally, the initial search index can be passed. </description> </method> <method name="format"> @@ -947,7 +953,7 @@ <argument index="1" name="len" type="int" default="-1"> </argument> <description> - Returns part of the string from the position [code]from[/code] with length [code]len[/code]. Argument [code]len[/code] is optional and using -1 will return remaining characters from given position. + Returns part of the string from the position [code]from[/code] with length [code]len[/code]. Argument [code]len[/code] is optional and using [code]-1[/code] will return remaining characters from given position. </description> </method> <method name="to_ascii"> |