Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
String Slicing 2/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

String Slicing 2/2

We can also get a substring from a string using simple slicing.

First, let's look at the syntax of slicing. string[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.

Tarefa

You have such a string 1234567890. You have to carry out the following steps:

  1. print elements from beginning till the end(as a result you have to get: 1234567890)
  2. print elements from the 5th element till the end(as a result you have to get: 567890)
  3. print elements in a range 2-7(as a result you have to get: 34567)

Tarefa

You have such a string 1234567890. You have to carry out the following steps:

  1. print elements from beginning till the end(as a result you have to get: 1234567890)
  2. print elements from the 5th element till the end(as a result you have to get: 567890)
  3. print elements in a range 2-7(as a result you have to get: 34567)

Tudo estava claro?

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

String Slicing 2/2

We can also get a substring from a string using simple slicing.

First, let's look at the syntax of slicing. string[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.

Tarefa

You have such a string 1234567890. You have to carry out the following steps:

  1. print elements from beginning till the end(as a result you have to get: 1234567890)
  2. print elements from the 5th element till the end(as a result you have to get: 567890)
  3. print elements in a range 2-7(as a result you have to get: 34567)

Tarefa

You have such a string 1234567890. You have to carry out the following steps:

  1. print elements from beginning till the end(as a result you have to get: 1234567890)
  2. print elements from the 5th element till the end(as a result you have to get: 567890)
  3. print elements in a range 2-7(as a result you have to get: 34567)

Tudo estava claro?

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

String Slicing 2/2

We can also get a substring from a string using simple slicing.

First, let's look at the syntax of slicing. string[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.

Tarefa

You have such a string 1234567890. You have to carry out the following steps:

  1. print elements from beginning till the end(as a result you have to get: 1234567890)
  2. print elements from the 5th element till the end(as a result you have to get: 567890)
  3. print elements in a range 2-7(as a result you have to get: 34567)

Tarefa

You have such a string 1234567890. You have to carry out the following steps:

  1. print elements from beginning till the end(as a result you have to get: 1234567890)
  2. print elements from the 5th element till the end(as a result you have to get: 567890)
  3. print elements in a range 2-7(as a result you have to get: 34567)

Tudo estava claro?

We can also get a substring from a string using simple slicing.

First, let's look at the syntax of slicing. string[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.

Tarefa

You have such a string 1234567890. You have to carry out the following steps:

  1. print elements from beginning till the end(as a result you have to get: 1234567890)
  2. print elements from the 5th element till the end(as a result you have to get: 567890)
  3. print elements in a range 2-7(as a result you have to get: 34567)

Seção 3. Capítulo 6
Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt