Learn String Manipulation by Building a Cipher - Step 5

Tell us what’s happening:

text = ‘Hello World’
W = text[7]
print (7)

In this code, we calculate the position of each letter. For example, in ‘Hello world,’ ‘W’ is at position 7. We already know ‘W’ is at position 7, so why do we need an extra command to find this information? It seems like a waste of time compared to the straightforward code above.

If we want to find the position of any letter in ‘Hello world’, how would we write the code? This code is designed for learning purposes.

Your code so far

# User Editable Region

text = 'Hello World'

# User Editable Region

Your browser information:

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 5

Hi there and welcome to our community!

The purpose of this exercise is to teach you about zero-based indexing. This can be used to access or manipulate data (such as strings, lists etc). Often, we will not know the contents of a string or list, as these may be determined by user input or data from other sources.

For instance, we know that in the string ‘Hello World’, the letter H is at index 0, and the letter W is at index 6.
However, this is currently assigned as the value of the variable text, which could be assigned any arbitrary value.


text = 'Some Random Text'

# prints S

# prints R

text = 'Some Alternative Text'

# prints A

For this exercise, you should:

print just the character at index 6 .

So, using the above example, you should be able to access the variable text and print the character at index 6.

You can do this using the .find() method, which you will learn about later in this project.



Please do not open multiple threads per step. You’ve already been silenced once, please try not to let it happen again.

Do you have a question?