Back to Freecodecamp

Step 30

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/65688a50e6c998a21d8e41d3.md

latest1.2 KB
Original Source

--description--

Strings are immutable, which means they cannot be changed once created. For example, you might think that the following code changes the value of my_string into the string 'train', but this is not valid:

py
my_string = 'brain'
my_string[0] = 't'

Confirm that by using the bracket notation to access the first letter in text and try to change it into a character of your choice. You will see the ouput disappear and an error appear.

--hints--

You should still have text = 'Hello World' in your code.

js
assert.match(code, /^text\s*=\s*("|')Hello World\1/m)

You should access the first letter in text with text[0].

js
assert.match(code, /^text\s*\[\s*0\s*\]\s*/m)

You should use the = operator to assign a character of your choice to text[0]. Don't forget to enclose the character in either single or double quotes.

js
assert.match(code, /^text\s*\[\s*0\s*\]\s*\=\s*("|').\1/m)

--seed--

--seed-contents--

py
--fcc-editable-region--
text = 'Hello World'

--fcc-editable-region--
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'

for char in text.lower():
    index = alphabet.find(char)
    print(char, index)
    new_index = index + shift