mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
classref: Sync with current master branch (c6c464c)
This commit is contained in:
@@ -704,7 +704,7 @@ Returns the index of the **first** **case-insensitive** occurrence of ``what`` i
|
||||
|
||||
Formats the string by replacing all occurrences of ``placeholder`` with the elements of ``values``.
|
||||
|
||||
\ ``values`` can be a :ref:`Dictionary<class_Dictionary>` or an :ref:`Array<class_Array>`. Any underscores in ``placeholder`` will be replaced with the corresponding keys in advance. Array elements use their index as keys.
|
||||
\ ``values`` can be a :ref:`Dictionary<class_Dictionary>`, an :ref:`Array<class_Array>` or an :ref:`Object<class_Object>`. Any underscores in ``placeholder`` will be replaced with the corresponding keys in advance. Array elements use their index as keys.
|
||||
|
||||
::
|
||||
|
||||
@@ -723,6 +723,14 @@ Some additional handling is performed when ``values`` is an :ref:`Array<class_Ar
|
||||
print("User {} is {}.".format([42, "Godot"], "{}"))
|
||||
print("User {id} is {name}.".format([["id", 42], ["name", "Godot"]]))
|
||||
|
||||
When passing an :ref:`Object<class_Object>`, the property names from :ref:`Object.get_property_list<class_Object_method_get_property_list>` are used as keys.
|
||||
|
||||
::
|
||||
|
||||
# Prints: Visible true, position (0, 0).
|
||||
var node = Node2D.new()
|
||||
print("Visible {visible}, position {position}".format(node))
|
||||
|
||||
See also the :doc:`GDScript format string <../tutorials/scripting/gdscript/gdscript_format_string>` tutorial.
|
||||
|
||||
\ **Note:** The replacement of placeholders is not done all at once, instead each placeholder is replaced in the order they are passed, this means that if one of the replacement strings contains a key it will also be replaced. This can be very powerful, but can also cause unexpected results if you are not careful. If you do not need to perform replacement in the replacement strings, make sure your replacements do not contain placeholders to ensure reliable results.
|
||||
|
||||
Reference in New Issue
Block a user