String Slicing 1/2
To get get a substring from a string, you have to use slice()
function.
The syntax of slice()
function:.
slice(start: end: step)
respectively:
- start -- the index from which to start slicing.
- end -- the index at which the slicing ends.
- step -- this parameter determines the increments between the indices.
Ending index is
up to but not including
.
Indexing starts from 0.
It's time for an example.
12345678910# String slicing string ='Python' # Using slice constructor string_1 = slice(4) string_2 = slice(2, 6, 2) string_3 = slice(-1, -5, -2) print(string[string_1]) print(string[string_2]) print(string[string_3])
Swipe to start coding
You have such string hello, world
. Using slice()
constructor you have to get such string: ll
, eowl
, world
. Use only positive indexing.
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Resumir este capítulo
Explicar el código en file
Explicar por qué file no resuelve la tarea
Awesome!
Completion rate improved to 3.85
String Slicing 1/2
Desliza para mostrar el menú
To get get a substring from a string, you have to use slice()
function.
The syntax of slice()
function:.
slice(start: end: step)
respectively:
- start -- the index from which to start slicing.
- end -- the index at which the slicing ends.
- step -- this parameter determines the increments between the indices.
Ending index is
up to but not including
.
Indexing starts from 0.
It's time for an example.
12345678910# String slicing string ='Python' # Using slice constructor string_1 = slice(4) string_2 = slice(2, 6, 2) string_3 = slice(-1, -5, -2) print(string[string_1]) print(string[string_2]) print(string[string_3])
Swipe to start coding
You have such string hello, world
. Using slice()
constructor you have to get such string: ll
, eowl
, world
. Use only positive indexing.
Solución
¡Gracias por tus comentarios!
Awesome!
Completion rate improved to 3.85single