Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
String Slicing | 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

bookString Slicing

What if we want to extract multiple symbols at once? Surely, we can extract them one by one, but it's a bit irrational, isn't it? Surely, it is irrational.

To do this, we can use slicing. Slice syntax allows us to extract a range of characters. To extract elements from starting index m to index n we use string[m:n+1]. Yes, note that the last index is not included, therefore if we want to extract the element with index 5 (for example) as the last we need to pass 6 as the next index after :.

We can also extract all the elements from a certain position till the end by leaving out the last index (like s[3:] will extract all the elements starting from index 3). The same logic applies if we leave out the first index - in this case, we will get all the elements to a specific one (like s[:5] will extract all the elements to index 4).

Завдання

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

  1. Extract all the elements starting from index 7 to index 18 (including both left and right boundaries).
  2. Extract all the elements starting from the index 20 (including the boundary).

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

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

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

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

bookString Slicing

What if we want to extract multiple symbols at once? Surely, we can extract them one by one, but it's a bit irrational, isn't it? Surely, it is irrational.

To do this, we can use slicing. Slice syntax allows us to extract a range of characters. To extract elements from starting index m to index n we use string[m:n+1]. Yes, note that the last index is not included, therefore if we want to extract the element with index 5 (for example) as the last we need to pass 6 as the next index after :.

We can also extract all the elements from a certain position till the end by leaving out the last index (like s[3:] will extract all the elements starting from index 3). The same logic applies if we leave out the first index - in this case, we will get all the elements to a specific one (like s[:5] will extract all the elements to index 4).

Завдання

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

  1. Extract all the elements starting from index 7 to index 18 (including both left and right boundaries).
  2. Extract all the elements starting from the index 20 (including the boundary).

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

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

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

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

bookString Slicing

What if we want to extract multiple symbols at once? Surely, we can extract them one by one, but it's a bit irrational, isn't it? Surely, it is irrational.

To do this, we can use slicing. Slice syntax allows us to extract a range of characters. To extract elements from starting index m to index n we use string[m:n+1]. Yes, note that the last index is not included, therefore if we want to extract the element with index 5 (for example) as the last we need to pass 6 as the next index after :.

We can also extract all the elements from a certain position till the end by leaving out the last index (like s[3:] will extract all the elements starting from index 3). The same logic applies if we leave out the first index - in this case, we will get all the elements to a specific one (like s[:5] will extract all the elements to index 4).

Завдання

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

  1. Extract all the elements starting from index 7 to index 18 (including both left and right boundaries).
  2. Extract all the elements starting from the index 20 (including the boundary).

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

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

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

What if we want to extract multiple symbols at once? Surely, we can extract them one by one, but it's a bit irrational, isn't it? Surely, it is irrational.

To do this, we can use slicing. Slice syntax allows us to extract a range of characters. To extract elements from starting index m to index n we use string[m:n+1]. Yes, note that the last index is not included, therefore if we want to extract the element with index 5 (for example) as the last we need to pass 6 as the next index after :.

We can also extract all the elements from a certain position till the end by leaving out the last index (like s[3:] will extract all the elements starting from index 3). The same logic applies if we leave out the first index - in this case, we will get all the elements to a specific one (like s[:5] will extract all the elements to index 4).

Завдання

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

  1. Extract all the elements starting from index 7 to index 18 (including both left and right boundaries).
  2. Extract all the elements starting from the index 20 (including the boundary).

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 1. Розділ 4
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt