Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Slice the Phrase | Strings
Data Types in Python

Glissez pour afficher le menu

book
Slice the Phrase

If we are certain that we intend to extract all characters from position 5 to the end of the string, there is no need to employ the string[5 : ending_index] syntax. Python offers a diverse array of built-in functions, and it adjusts its syntax to suit your specific needs.
Let’s look at this phrase:

1234
string = "Push beyond your limits" phrase = string[5:] print(phrase)
copy

Alternatively, this also applies when you require the extraction of a phrase starting from the initial point up to a specified index:

123
string = "Push beyond your limits" phrase = string[:11] print(phrase)
copy
Tâche

Swipe to start coding

It's your turn! Follow this algorithm:

  1. Extract the phrase Get a foot from the first string and assign it to the variable phrase1.
  2. Extract the phrase away from the second string and assign it to the variable phrase2 (using negative indexation is more reasonable here).

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 6
Nous sommes désolés de vous informer que quelque chose s'est mal passé. Qu'est-il arrivé ?

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

book
Slice the Phrase

If we are certain that we intend to extract all characters from position 5 to the end of the string, there is no need to employ the string[5 : ending_index] syntax. Python offers a diverse array of built-in functions, and it adjusts its syntax to suit your specific needs.
Let’s look at this phrase:

1234
string = "Push beyond your limits" phrase = string[5:] print(phrase)
copy

Alternatively, this also applies when you require the extraction of a phrase starting from the initial point up to a specified index:

123
string = "Push beyond your limits" phrase = string[:11] print(phrase)
copy
Tâche

Swipe to start coding

It's your turn! Follow this algorithm:

  1. Extract the phrase Get a foot from the first string and assign it to the variable phrase1.
  2. Extract the phrase away from the second string and assign it to the variable phrase2 (using negative indexation is more reasonable here).

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 6
Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Nous sommes désolés de vous informer que quelque chose s'est mal passé. Qu'est-il arrivé ?
some-alt