Contenido del Curso
Tipos de Datos en Python
Tipos de Datos en Python
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:
string = "Push beyond your limits" phrase = string[5:] print(phrase)
Alternatively, this also applies when you require the extraction of a phrase starting from the initial point up to a specified index:
string = "Push beyond your limits" phrase = string[:11] print(phrase)
Swipe to begin your solution
Now it's your turn! Follow these steps:
-
Use slicing to extract the phrase
"Get a foot"
from the first string and assign it to the variablephrase1
. -
Use slicing to extract the phrase
"away"
from the second string and assign it to the variablephrase2
(using negative indexing is recommended here).
Solución
¡Gracias por tus comentarios!
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:
string = "Push beyond your limits" phrase = string[5:] print(phrase)
Alternatively, this also applies when you require the extraction of a phrase starting from the initial point up to a specified index:
string = "Push beyond your limits" phrase = string[:11] print(phrase)
Swipe to begin your solution
Now it's your turn! Follow these steps:
-
Use slicing to extract the phrase
"Get a foot"
from the first string and assign it to the variablephrase1
. -
Use slicing to extract the phrase
"away"
from the second string and assign it to the variablephrase2
(using negative indexing is recommended here).
Solución
¡Gracias por tus comentarios!