Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Negative Indexing | Basic Concepts
String Manipulation in Python
course content

Зміст курсу

String Manipulation in Python

String Manipulation in Python

1. Basic Concepts
2. String Methods
3. Strings Formatting

bookNegative Indexing

Sometimes, we want to move backward, i.e. starting with the very last symbol. Of course, we can count a number of symbols in a string, and then use it for our purposes. But it is a bit irrational, isn't it?

In Python, like for lists or tuples, we can access the very last element by using negative index -1. With negative indexing, enumeration starts with 1 this time, i.e. the very last element has index -1, the last but one -2, and so on...

Note

You can reverse a string by using [::-1]. This indexation means start at the end of string, end at the start (index 0), and move with step -1 (backward).

Завдання
test

Swipe to show code editor

Given variable course with the string String Manipulation in Python. Your tasks are:

  1. Extract the capital P by using positive indexing.
  2. Extract the capital P by using negative indexing.

Hint: this string has 29 symbols, therefore the very last element has an index of 28.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 6
toggle bottom row

bookNegative Indexing

Sometimes, we want to move backward, i.e. starting with the very last symbol. Of course, we can count a number of symbols in a string, and then use it for our purposes. But it is a bit irrational, isn't it?

In Python, like for lists or tuples, we can access the very last element by using negative index -1. With negative indexing, enumeration starts with 1 this time, i.e. the very last element has index -1, the last but one -2, and so on...

Note

You can reverse a string by using [::-1]. This indexation means start at the end of string, end at the start (index 0), and move with step -1 (backward).

Завдання
test

Swipe to show code editor

Given variable course with the string String Manipulation in Python. Your tasks are:

  1. Extract the capital P by using positive indexing.
  2. Extract the capital P by using negative indexing.

Hint: this string has 29 symbols, therefore the very last element has an index of 28.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 6
toggle bottom row

bookNegative Indexing

Sometimes, we want to move backward, i.e. starting with the very last symbol. Of course, we can count a number of symbols in a string, and then use it for our purposes. But it is a bit irrational, isn't it?

In Python, like for lists or tuples, we can access the very last element by using negative index -1. With negative indexing, enumeration starts with 1 this time, i.e. the very last element has index -1, the last but one -2, and so on...

Note

You can reverse a string by using [::-1]. This indexation means start at the end of string, end at the start (index 0), and move with step -1 (backward).

Завдання
test

Swipe to show code editor

Given variable course with the string String Manipulation in Python. Your tasks are:

  1. Extract the capital P by using positive indexing.
  2. Extract the capital P by using negative indexing.

Hint: this string has 29 symbols, therefore the very last element has an index of 28.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Sometimes, we want to move backward, i.e. starting with the very last symbol. Of course, we can count a number of symbols in a string, and then use it for our purposes. But it is a bit irrational, isn't it?

In Python, like for lists or tuples, we can access the very last element by using negative index -1. With negative indexing, enumeration starts with 1 this time, i.e. the very last element has index -1, the last but one -2, and so on...

Note

You can reverse a string by using [::-1]. This indexation means start at the end of string, end at the start (index 0), and move with step -1 (backward).

Завдання
test

Swipe to show code editor

Given variable course with the string String Manipulation in Python. Your tasks are:

  1. Extract the capital P by using positive indexing.
  2. Extract the capital P by using negative indexing.

Hint: this string has 29 symbols, therefore the very last element has an index of 28.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 1. Розділ 6
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt