Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Slice the Word | Рядки
Типи даних у Python
course content

Зміст курсу

Типи даних у Python

Типи даних у Python

1. Знайомство з числами в Python
2. Істина чи брехня?
3. Рядки
4. Поєднання всіх тем разом

book
Slice the Word

In the preceding chapter, we discussed the method for extracting a particular character from a string. However, what procedures can we employ to obtain a particular substring with a consecutive sequence of characters? The most straightforward approach is to employ a technique called slicing.

This operation allows us to get not only one symbol, but a combination of symbols per operation. Take a look at the syntax:

123
string = "Extract the word kitten" kitten = string[17:23] print(kitten)
copy

The syntax is string[starting_index : ending_index], but try to double check the indexation for the word kitten.

k has an index of 17, but the n character has an index of 22, not 23.

Why was 23 written?

The solution is straightforward. The ending index is exclusive, meaning that when we write 23, Python does not include this index but considers the one immediately before it.

Завдання
test

Swipe to begin your solution

Mastering string manipulation is essential, and it will greatly improve your skills in handling data structures.

  1. Use slicing to extract the word "puppy" and assign it to the variable puppy
  2. Use slicing to extract the word "nestling" and assign it to the variable nestling

Make sure to use only the techniques covered in this chapter. 😇

Рішення

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

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

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

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

book
Slice the Word

In the preceding chapter, we discussed the method for extracting a particular character from a string. However, what procedures can we employ to obtain a particular substring with a consecutive sequence of characters? The most straightforward approach is to employ a technique called slicing.

This operation allows us to get not only one symbol, but a combination of symbols per operation. Take a look at the syntax:

123
string = "Extract the word kitten" kitten = string[17:23] print(kitten)
copy

The syntax is string[starting_index : ending_index], but try to double check the indexation for the word kitten.

k has an index of 17, but the n character has an index of 22, not 23.

Why was 23 written?

The solution is straightforward. The ending index is exclusive, meaning that when we write 23, Python does not include this index but considers the one immediately before it.

Завдання
test

Swipe to begin your solution

Mastering string manipulation is essential, and it will greatly improve your skills in handling data structures.

  1. Use slicing to extract the word "puppy" and assign it to the variable puppy
  2. Use slicing to extract the word "nestling" and assign it to the variable nestling

Make sure to use only the techniques covered in this chapter. 😇

Рішення

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

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

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

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