</>
Topic 8 of 10
Theory

Working with strings

Strings have many handy methods:

s = "  Hello, World  "
print(s.strip())          # "Hello, World" — no spaces at the ends
print(s.lower())          # lowercase
print(s.replace("World", "Python"))
print("a-b-c".split("-")) # ['a', 'b', 'c']
print("-".join(["a", "b"]))  # "a-b"

The slice s[::-1] reverses a string. ord("a") gives a character's code, chr(97) gives a character by its code. c.isalpha() checks that a character is a letter.

Palindrome

Easy+10 XP

Check whether a phrase reads the same forwards and backwards. Ignore case and spaces.

is_palindrome("Never odd or even") → True
main.pyLoading Python…
Output
Press "Check" to run the tests