Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Get Acquainted With Indexation | Strings
Data Types in Python
course content

Course Content

Data Types in Python

Data Types in Python

1. Getting Familiar With Numbers in Python
2. True or False?
3. Strings
4. Bring All the Topics Together

bookGet Acquainted With Indexation

You may have heard about indexation before.😃

It may not present a significant challenge for you, but some programmers consider indexing one of the more intricate subjects. However, I disagree with this assertion. Therefore, I recommend engaging in several practical exercises to minimize the likelihood of making mistakes in such situations.

The main point is that indexation starts from zero. Let's look at the word codefinity. c has the index 0, o has the index 1, and so on, and y has the index 9:

To determine the character associated with a specific index, employ the following syntax: word[index_number]. For instance, when working with the word codefinity, to obtain the initial character c, you should utilize the subsequent code: codefinity[0].

1234
string = "codefinity" print("Print the c symbol:", string[0]) print("Print the o symbol:", string[1]) print("Print the y symbol:", string[9])
copy

Be careful, pay attention, and do not let the following statement be part of your code output:

string index out of range

This means that you tried to reach an index that doesn't exist in your word, like 10 for the word codefinity.

It should be noted that spaces are as valuable as other symbols, so subsequent strings are not equal because the last symbol of the first string is n and it has the index 5, but the last symbol of the second string is space and it has the index 6:

1234
string1 = "Python" string2 = "Python " print("The last symbol of the first string is", string1[5]) print("The last symbol of the second string is", string2[6])
copy

Task

I appreciate your desire to study; it's awesome that you've completed so many tasks!😍

Here, you are given two strings.

Use indexing to extract specific characters from string1 and string2 in order to form the phrase I l o v e y o u in the output.

To deal with this task, you must work with indexation only; do not use additional functions.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 3
toggle bottom row

bookGet Acquainted With Indexation

You may have heard about indexation before.😃

It may not present a significant challenge for you, but some programmers consider indexing one of the more intricate subjects. However, I disagree with this assertion. Therefore, I recommend engaging in several practical exercises to minimize the likelihood of making mistakes in such situations.

The main point is that indexation starts from zero. Let's look at the word codefinity. c has the index 0, o has the index 1, and so on, and y has the index 9:

To determine the character associated with a specific index, employ the following syntax: word[index_number]. For instance, when working with the word codefinity, to obtain the initial character c, you should utilize the subsequent code: codefinity[0].

1234
string = "codefinity" print("Print the c symbol:", string[0]) print("Print the o symbol:", string[1]) print("Print the y symbol:", string[9])
copy

Be careful, pay attention, and do not let the following statement be part of your code output:

string index out of range

This means that you tried to reach an index that doesn't exist in your word, like 10 for the word codefinity.

It should be noted that spaces are as valuable as other symbols, so subsequent strings are not equal because the last symbol of the first string is n and it has the index 5, but the last symbol of the second string is space and it has the index 6:

1234
string1 = "Python" string2 = "Python " print("The last symbol of the first string is", string1[5]) print("The last symbol of the second string is", string2[6])
copy

Task

I appreciate your desire to study; it's awesome that you've completed so many tasks!😍

Here, you are given two strings.

Use indexing to extract specific characters from string1 and string2 in order to form the phrase I l o v e y o u in the output.

To deal with this task, you must work with indexation only; do not use additional functions.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 3
toggle bottom row

bookGet Acquainted With Indexation

You may have heard about indexation before.😃

It may not present a significant challenge for you, but some programmers consider indexing one of the more intricate subjects. However, I disagree with this assertion. Therefore, I recommend engaging in several practical exercises to minimize the likelihood of making mistakes in such situations.

The main point is that indexation starts from zero. Let's look at the word codefinity. c has the index 0, o has the index 1, and so on, and y has the index 9:

To determine the character associated with a specific index, employ the following syntax: word[index_number]. For instance, when working with the word codefinity, to obtain the initial character c, you should utilize the subsequent code: codefinity[0].

1234
string = "codefinity" print("Print the c symbol:", string[0]) print("Print the o symbol:", string[1]) print("Print the y symbol:", string[9])
copy

Be careful, pay attention, and do not let the following statement be part of your code output:

string index out of range

This means that you tried to reach an index that doesn't exist in your word, like 10 for the word codefinity.

It should be noted that spaces are as valuable as other symbols, so subsequent strings are not equal because the last symbol of the first string is n and it has the index 5, but the last symbol of the second string is space and it has the index 6:

1234
string1 = "Python" string2 = "Python " print("The last symbol of the first string is", string1[5]) print("The last symbol of the second string is", string2[6])
copy

Task

I appreciate your desire to study; it's awesome that you've completed so many tasks!😍

Here, you are given two strings.

Use indexing to extract specific characters from string1 and string2 in order to form the phrase I l o v e y o u in the output.

To deal with this task, you must work with indexation only; do not use additional functions.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

You may have heard about indexation before.😃

It may not present a significant challenge for you, but some programmers consider indexing one of the more intricate subjects. However, I disagree with this assertion. Therefore, I recommend engaging in several practical exercises to minimize the likelihood of making mistakes in such situations.

The main point is that indexation starts from zero. Let's look at the word codefinity. c has the index 0, o has the index 1, and so on, and y has the index 9:

To determine the character associated with a specific index, employ the following syntax: word[index_number]. For instance, when working with the word codefinity, to obtain the initial character c, you should utilize the subsequent code: codefinity[0].

1234
string = "codefinity" print("Print the c symbol:", string[0]) print("Print the o symbol:", string[1]) print("Print the y symbol:", string[9])
copy

Be careful, pay attention, and do not let the following statement be part of your code output:

string index out of range

This means that you tried to reach an index that doesn't exist in your word, like 10 for the word codefinity.

It should be noted that spaces are as valuable as other symbols, so subsequent strings are not equal because the last symbol of the first string is n and it has the index 5, but the last symbol of the second string is space and it has the index 6:

1234
string1 = "Python" string2 = "Python " print("The last symbol of the first string is", string1[5]) print("The last symbol of the second string is", string2[6])
copy

Task

I appreciate your desire to study; it's awesome that you've completed so many tasks!😍

Here, you are given two strings.

Use indexing to extract specific characters from string1 and string2 in order to form the phrase I l o v e y o u in the output.

To deal with this task, you must work with indexation only; do not use additional functions.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 3. Chapter 3
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt