2. Slicing¶
Slice from the first index to the one before the second
Print output (drag lower right corner to resize)
|
Activity: CodeLens 2.1 (cl_l18_2a_en)
We can omit indices by substituting the corresponding end and we can also have negative indices: -1 is the last one, -2 the penultimate
Print output (drag lower right corner to resize)
|
Activity: CodeLens 2.2 (cl_l18_2b_en)
2.1. Slice increment¶
I can use an increment when slicing the string
Print output (drag lower right corner to resize)
|
Activity: CodeLens 2.1.1 (cl_l18_2c_en)
Check if a word is a palindrome
xxxxxxxxxx
word = input("Word: ")
if word == word[::-1]:
print("%s is a palindrome" % word)
else:
print("%s is not a palindrome" % word)
Activity: 2.1.2 ActiveCode (ac_l18_2_en)
You have attempted 1 of 3 activities on this page