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

Slicing allows you to extract a substring — a sequence of characters from a string. Unlike indexing (which gives one character), slicing returns a portion of the string.

python

start — the index where the slice begins (inclusive)

end — the index where the slice stops (exclusive)

So the character at start is included, but the character at end is not.

123
record = "Invoice INV-2024-007 paid" invoice_code = record[8:21] print(invoice_code) # Output: INV-2024-007
copy

In this case:

  • 'I' is at index 8;
  • '7' is at index 20;

So we use [8:21] to get the full invoice code

Завдання

Swipe to start coding

Given the string:

"asset and liability, debit and credit"

  1. Use slicing to extract the word "asset" and assign it to the variable asset.

  2. Use slicing to extract the word "debit" and assign it to the variable debit. Make sure to use slicing only — no string methods or manual typing.

Рішення

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

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

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

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

book
Slice the Word

Slicing allows you to extract a substring — a sequence of characters from a string. Unlike indexing (which gives one character), slicing returns a portion of the string.

python

start — the index where the slice begins (inclusive)

end — the index where the slice stops (exclusive)

So the character at start is included, but the character at end is not.

123
record = "Invoice INV-2024-007 paid" invoice_code = record[8:21] print(invoice_code) # Output: INV-2024-007
copy

In this case:

  • 'I' is at index 8;
  • '7' is at index 20;

So we use [8:21] to get the full invoice code

Завдання

Swipe to start coding

Given the string:

"asset and liability, debit and credit"

  1. Use slicing to extract the word "asset" and assign it to the variable asset.

  2. Use slicing to extract the word "debit" and assign it to the variable debit. Make sure to use slicing only — no string methods or manual typing.

Рішення

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

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

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

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