Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Slice the Word | Strings
Tipos de Dados em Python
course content

Conteúdo do Curso

Tipos de Dados em Python

Tipos de Dados em Python

1. Conhecendo os números em Python
2. Verdadeiro ou falso?
3. Strings
4. Reunindo todos os tópicos

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

Tarefa

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.

Solução

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 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

Tarefa

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.

Solução

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 4
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt