Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Slice the Word | Python String Manipulation
Data Types in Python
course content

Cursusinhoud

Data Types in Python

Data Types in Python

1. Getting Familiar With Numbers in Python
2. Mastering Boolean Logic in Python
3. Python String Manipulation
4. Bring All the Topics Together

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

Taak

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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 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

Taak

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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 4
Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Onze excuses dat er iets mis is gegaan. Wat is er gebeurd?
some-alt