added another property of string with code samples (#29224)
This commit is contained in:
committed by
Randell Dawson
parent
6c82a07b2d
commit
2c1a838990
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user