From d7918dbc00518aa92193624241a6cf1bc2d2bb83 Mon Sep 17 00:00:00 2001 From: Mukesh Jha Date: Wed, 19 Dec 2018 08:54:09 +0530 Subject: [PATCH] Added the way to modify immutable string. (#25334) * Added the way to modify immutable string. * Formatting changes --- guide/english/python/data-structures/strings/index.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/guide/english/python/data-structures/strings/index.md b/guide/english/python/data-structures/strings/index.md index 6855f9fa17..981751568b 100644 --- a/guide/english/python/data-structures/strings/index.md +++ b/guide/english/python/data-structures/strings/index.md @@ -20,7 +20,15 @@ Python allows `str` objects, or _strings_, to be expressed in a few different wa File "", line 1, in TypeError: 'str' object does not support item assignment - + Instead, you can convert the string into a list, modify the list element (string character) you wish to change, and then join the list elements back to a string, like so: + + >>> foo = "my string" + >>> foo_list_form = list(foo) + >>> foo_list_form[0] = "a" + >>> foo = ' '.join(foo_list_form) + >>> print(foo) + ay string # The required output + ## Reference: Text Sequence Type _str_