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.
string[start : end]
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.
123record = "Invoice INV-2024-007 paid" invoice_code = record[8:21] print(invoice_code) # Output: INV-2024-007
In this case:
'I'
is at index8
;- '
7'
is at index20
;
So we use [8:21]
to get the full invoice code
Swipe to start coding
Given the string:
"asset and liability, debit and credit"
-
Use slicing to extract the word
"asset"
and assign it to the variable asset. -
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.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Awesome!
Completion rate improved to 3.03Awesome!
Completion rate improved to 3.03
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.
string[start : end]
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.
123record = "Invoice INV-2024-007 paid" invoice_code = record[8:21] print(invoice_code) # Output: INV-2024-007
In this case:
'I'
is at index8
;- '
7'
is at index20
;
So we use [8:21]
to get the full invoice code
Swipe to start coding
Given the string:
"asset and liability, debit and credit"
-
Use slicing to extract the word
"asset"
and assign it to the variable asset. -
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.
Lösung
Danke für Ihr Feedback!
single
Awesome!
Completion rate improved to 3.03
Slice the Word
Swipe um das Menü anzuzeigen
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.
string[start : end]
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.
123record = "Invoice INV-2024-007 paid" invoice_code = record[8:21] print(invoice_code) # Output: INV-2024-007
In this case:
'I'
is at index8
;- '
7'
is at index20
;
So we use [8:21]
to get the full invoice code
Swipe to start coding
Given the string:
"asset and liability, debit and credit"
-
Use slicing to extract the word
"asset"
and assign it to the variable asset. -
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.
Lösung
Danke für Ihr Feedback!