Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Looking Inside the Strings | Strings
Python Data Types
course content

Зміст курсу

Python Data Types

Python Data Types

1. Numeric Types
2. Boolean Type
3. Strings

book Looking Inside the Strings

We can use indexing to get a specific character from a string or if we need to get a range of characters, then we use slices. It is important to note that the value of the index must be an integer. In Python, indexing starts from 0. If we try to access the string item outside the range then we will get an error Index Error. In Python there is also the possibility of negative indexing, in this case -1 is the index of the last element, -2 is the penultimate one, and so on.

12345678910
# Accessing string characters string = 'Hello, World' print('string = ', string) # Accessing the first character print(f'The first character is "{string[0]}"') # Accessing the last character print(f'The last character is "{string[-1]}"')
copy

Ending index is up to but not including.

Indexing starts from 0.

Завдання

Swipe to show code editor

test

You have such string watermelon. You have to get such characters: n, m, l, a. Use only positive indexing.

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

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

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

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

book Looking Inside the Strings

We can use indexing to get a specific character from a string or if we need to get a range of characters, then we use slices. It is important to note that the value of the index must be an integer. In Python, indexing starts from 0. If we try to access the string item outside the range then we will get an error Index Error. In Python there is also the possibility of negative indexing, in this case -1 is the index of the last element, -2 is the penultimate one, and so on.

12345678910
# Accessing string characters string = 'Hello, World' print('string = ', string) # Accessing the first character print(f'The first character is "{string[0]}"') # Accessing the last character print(f'The last character is "{string[-1]}"')
copy

Ending index is up to but not including.

Indexing starts from 0.

Завдання

Swipe to show code editor

test

You have such string watermelon. You have to get such characters: n, m, l, a. Use only positive indexing.

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

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

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

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

book Looking Inside the Strings

We can use indexing to get a specific character from a string or if we need to get a range of characters, then we use slices. It is important to note that the value of the index must be an integer. In Python, indexing starts from 0. If we try to access the string item outside the range then we will get an error Index Error. In Python there is also the possibility of negative indexing, in this case -1 is the index of the last element, -2 is the penultimate one, and so on.

12345678910
# Accessing string characters string = 'Hello, World' print('string = ', string) # Accessing the first character print(f'The first character is "{string[0]}"') # Accessing the last character print(f'The last character is "{string[-1]}"')
copy

Ending index is up to but not including.

Indexing starts from 0.

Завдання

Swipe to show code editor

test

You have such string watermelon. You have to get such characters: n, m, l, a. Use only positive indexing.

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

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

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

We can use indexing to get a specific character from a string or if we need to get a range of characters, then we use slices. It is important to note that the value of the index must be an integer. In Python, indexing starts from 0. If we try to access the string item outside the range then we will get an error Index Error. In Python there is also the possibility of negative indexing, in this case -1 is the index of the last element, -2 is the penultimate one, and so on.

12345678910
# Accessing string characters string = 'Hello, World' print('string = ', string) # Accessing the first character print(f'The first character is "{string[0]}"') # Accessing the last character print(f'The last character is "{string[-1]}"')
copy

Ending index is up to but not including.

Indexing starts from 0.

Завдання

Swipe to show code editor

test

You have such string watermelon. You have to get such characters: n, m, l, a. Use only positive indexing.

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