Strings

Strings: indices, slices, the lower/upper/count methods and a palindrome check.

A Python string is very similar to a list of characters: indices, slices and len all apply. Reversing a string is a single slice: s[::-1]. Useful methods: s.lower() and s.upper() — case, s.count(x) — how many times a substring occurs, x in s — the "contains" check. Important: strings are immutable — s[0] = "a" raises an error. A modified string is always a new string.
Python

Enter a word, for example: hello

A palindrome is a word that reads the same in both directions. In Python the check takes one line: compare the string with its reversed copy.
Python

Palindrome check. Enter: racecar

Task: read a word and count the Latin vowels a, e, i, o, u in it (hint: a loop over the characters and a c in "aeiou" check; don't forget lower()). The problems "Reverse a String", "Palindrome Check" and "Count the Vowels" are attached to this lesson — solve all three and mark the lesson as completed.

Practice problems

Доска