Learn String Manipulation by Building a Cipher - Step 27

Tell us what’s happening:

totally lost no clue what to do?
Strings are immutable, which means they cannot be changed once created.

Use bracket notation to access the first letter in text and try to change it into a character of your choice.

Your code so far


/* User Editable Region */

text = 'Hello World'
text [1]

/* User Editable Region */

shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 27

Hi @code12009,

In programming languages like python, square bracket [ ] notation is commonly used to access specific elements within an array or characters within a string. If you want to access the first letter of a string, you can use square bracket notation along with the index of the character you want to retrieve.

so let us say we have a variable “school” and the value of school is “freecodecamp” and we want to access the second letter of “freecodecamp” this is how we will do it.
school[1]
if we want to attempt changing the letter ‘r’ in “freecodecamp” which is at index 1 to ‘w’ , this is how to do it.

school[1] = ‘w’

Note In Python, strings are immutable, meaning you cannot change individual characters directly using the square bracket notation.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.