2. Slicing

1x = "0123456789"
2print(x[0:2])
3print(x[1:2])
4print(x[2:4])
5print(x[0:5])
6print(x[1:8])
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 2.1 (cl_l18_2a_en)

1x = "0123456789"
2print(x[:2])
3print(x[4:])
4print(x[4:-1])
5print(x[-4:-1])
6print(x[:])
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 2.2 (cl_l18_2b_en)

2.1. Slice increment

  • I can use an increment when slicing the string

1texto = "papa cuando nace"
2print(texto[::2])
3print(texto[::-1])
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 2.1.1 (cl_l18_2c_en)

  • Check if a word is a palindrome

Activity: 2.1.2 ActiveCode (ac_l18_2_en)

You have attempted 1 of 3 activities on this page