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'
print(text)

# 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/124.0.0.0 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.

EXAMPLE:

text = 'Some Random Text'

print(text[0])
# prints S

print(text[5])
# prints R

text = 'Some Alternative Text'

print(text[5])
# 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.

https://www.w3schools.com/python/ref_string_find.asp

https://www.geeksforgeeks.org/python-string-find/

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?