Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
String Slicing 1/2 | Strings
Python Data Types
course content

Conteúdo do Curso

Python Data Types

Python Data Types

1. Numeric Types
2. Boolean Type
3. Strings

bookString Slicing 1/2

To get get a substring from a string, you have to use slice() function.

The syntax of slice() function:. slice(start: end: step) respectively:

  • start -- the index from which to start slicing.
  • end -- the index at which the slicing ends.
  • step -- this parameter determines the increments between the indices.

Ending index is up to but not including.

Indexing starts from 0.

It's time for an example.

12345678910
# String slicing string ='Python' # Using slice constructor string_1 = slice(4) string_2 = slice(2, 6, 2) string_3 = slice(-1, -5, -2) print(string[string_1]) print(string[string_2]) print(string[string_3])
copy
Tarefa

Swipe to show code editor

test

You have such string hello, world. Using slice() constructor you have to get such string: ll, eowl, world. Use only positive indexing.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 5
toggle bottom row

bookString Slicing 1/2

To get get a substring from a string, you have to use slice() function.

The syntax of slice() function:. slice(start: end: step) respectively:

  • start -- the index from which to start slicing.
  • end -- the index at which the slicing ends.
  • step -- this parameter determines the increments between the indices.

Ending index is up to but not including.

Indexing starts from 0.

It's time for an example.

12345678910
# String slicing string ='Python' # Using slice constructor string_1 = slice(4) string_2 = slice(2, 6, 2) string_3 = slice(-1, -5, -2) print(string[string_1]) print(string[string_2]) print(string[string_3])
copy
Tarefa

Swipe to show code editor

test

You have such string hello, world. Using slice() constructor you have to get such string: ll, eowl, world. Use only positive indexing.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 5
toggle bottom row

bookString Slicing 1/2

To get get a substring from a string, you have to use slice() function.

The syntax of slice() function:. slice(start: end: step) respectively:

  • start -- the index from which to start slicing.
  • end -- the index at which the slicing ends.
  • step -- this parameter determines the increments between the indices.

Ending index is up to but not including.

Indexing starts from 0.

It's time for an example.

12345678910
# String slicing string ='Python' # Using slice constructor string_1 = slice(4) string_2 = slice(2, 6, 2) string_3 = slice(-1, -5, -2) print(string[string_1]) print(string[string_2]) print(string[string_3])
copy
Tarefa

Swipe to show code editor

test

You have such string hello, world. Using slice() constructor you have to get such string: ll, eowl, world. Use only positive indexing.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

To get get a substring from a string, you have to use slice() function.

The syntax of slice() function:. slice(start: end: step) respectively:

  • start -- the index from which to start slicing.
  • end -- the index at which the slicing ends.
  • step -- this parameter determines the increments between the indices.

Ending index is up to but not including.

Indexing starts from 0.

It's time for an example.

12345678910
# String slicing string ='Python' # Using slice constructor string_1 = slice(4) string_2 = slice(2, 6, 2) string_3 = slice(-1, -5, -2) print(string[string_1]) print(string[string_2]) print(string[string_3])
copy
Tarefa

Swipe to show code editor

test

You have such string hello, world. Using slice() constructor you have to get such string: ll, eowl, world. Use only positive indexing.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 3. Capítulo 5
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
some-alt