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

Зміст курсу

Типи даних у Python

Типи даних у Python

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

book
Slicing Task

Slicing can be enhanced with a step argument, which allows you to extract characters at specific intervals.

This is useful when you want to select every second character, skip letters, or extract patterns from structured data like invoice numbers, transaction codes, or reports.

python
  • start: the index where slicing begins (inclusive)
  • end: the index where slicing ends (exclusive)
  • step: the interval (e.g., 2 means every second character)

Example

123
code = "TXN-2024-INV-0007" sliced = code[0:13:5] print(sliced) # Output: T2I
copy
  • We start at index 0
  • End at index 13 (exclusive)
  • Use a step of 5, which means: take every fifth character

Characters at indexes 0, 5, and 10 are 'T', '2', and 'I', so the output is 'T2I'.

This kind of slicing could be used to extract initials or control codes from structured strings in financial or document systems.

Завдання

Swipe to start coding

In an accounting system, filenames for financial reports are generated automatically. Each filename includes a prefix, the report type, and the year.

Your task is to use slicing with a step to extract the 1st and 3rd digits of the year (in this case, 2 and 2) from the filename. This result will serve as a simple year control code.

Рішення

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

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

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

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

book
Slicing Task

Slicing can be enhanced with a step argument, which allows you to extract characters at specific intervals.

This is useful when you want to select every second character, skip letters, or extract patterns from structured data like invoice numbers, transaction codes, or reports.

python
  • start: the index where slicing begins (inclusive)
  • end: the index where slicing ends (exclusive)
  • step: the interval (e.g., 2 means every second character)

Example

123
code = "TXN-2024-INV-0007" sliced = code[0:13:5] print(sliced) # Output: T2I
copy
  • We start at index 0
  • End at index 13 (exclusive)
  • Use a step of 5, which means: take every fifth character

Characters at indexes 0, 5, and 10 are 'T', '2', and 'I', so the output is 'T2I'.

This kind of slicing could be used to extract initials or control codes from structured strings in financial or document systems.

Завдання

Swipe to start coding

In an accounting system, filenames for financial reports are generated automatically. Each filename includes a prefix, the report type, and the year.

Your task is to use slicing with a step to extract the 1st and 3rd digits of the year (in this case, 2 and 2) from the filename. This result will serve as a simple year control code.

Рішення

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

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

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

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