From 2c1a838990aa114a68e9b53498961968d36e6f73 Mon Sep 17 00:00:00 2001 From: Tanuj Sharma Date: Thu, 28 Mar 2019 02:44:54 +0530 Subject: [PATCH] added another property of string with code samples (#29224) --- guide/english/python/data-structures/strings/index.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/guide/english/python/data-structures/strings/index.md b/guide/english/python/data-structures/strings/index.md index 981751568b3..1e475b7b1ae 100644 --- a/guide/english/python/data-structures/strings/index.md +++ b/guide/english/python/data-structures/strings/index.md @@ -19,6 +19,15 @@ Python allows `str` objects, or _strings_, to be expressed in a few different wa Traceback (most recent call last): File "", line 1, in TypeError: 'str' object does not support item assignment +* Indexable: You can access any character of `str` object by specifying its index. And as it supports slicing like in `list` and `tuple` objects. + + >>> foo = "my string" + >>> foo[3] + 's' + >>> foo[3:] + 'string' + >>> foo[::-1] + 'gnirts ym' 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: