> For the complete documentation index, see [llms.txt](https://docs.arkannis.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arkannis.net/programming/courses/python-pcap-31-03-course/overview-and-introduction/strings-are-immutable.md).

# Strings are Immutable

## Strings are Immutable

```python
my_var = 'abcdefg'

# To replace a with 1:
my_var[0] = "1" # This does not work, it will generate error:
# 'str' object does not support item assignment

# In order for it to work you will have to replace the whole string:
my_var = '1bcdefg'

# To do this programmatically you will have to:
my_var[1:] # Capture everything from the 2nd character
my_var = '1' + my_var[1:] # Add 1 to the captured string and reassign the variable
```
