Accessing String Elements
Now we know how we can create a string: both single and multiline. Now we need to learn how can we access certain elements in the string.
Elements in a string can be accessed by using indices. The very first index is 0, not 1. Therefore, if a string has 10 elements, the very last index will be 9.
Swipe to start coding
Given variable course
with the string String Manipulation in Python
. Your tasks are:
- Extract the element with index 7.
- Extract the 12th element.
Lösning
Tack för dina kommentarer!
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 4.35Awesome!
Completion rate improved to 4.35
Accessing String Elements
Now we know how we can create a string: both single and multiline. Now we need to learn how can we access certain elements in the string.
Elements in a string can be accessed by using indices. The very first index is 0, not 1. Therefore, if a string has 10 elements, the very last index will be 9.
Swipe to start coding
Given variable course
with the string String Manipulation in Python
. Your tasks are:
- Extract the element with index 7.
- Extract the 12th element.
Lösning
Tack för dina kommentarer!
single
Awesome!
Completion rate improved to 4.35
Accessing String Elements
Svep för att visa menyn
Now we know how we can create a string: both single and multiline. Now we need to learn how can we access certain elements in the string.
Elements in a string can be accessed by using indices. The very first index is 0, not 1. Therefore, if a string has 10 elements, the very last index will be 9.
Swipe to start coding
Given variable course
with the string String Manipulation in Python
. Your tasks are:
- Extract the element with index 7.
- Extract the 12th element.
Lösning
Tack för dina kommentarer!