added another property of string with code samples (#29224)

pull/31946/head^2
Tanuj Sharma 2019-03-28 02:44:54 +05:30 committed by Randell Dawson
parent 6c82a07b2d
commit 2c1a838990
1 changed files with 9 additions and 0 deletions

View File

@ -19,6 +19,15 @@ Python allows `str` objects, or _strings_, to be expressed in a few different wa
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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: