Skip to content
CCC Python Course

Strings

Stage
1
Module
M1.7
Lessons
1

In this module

  • Find how many characters a string holds with len().
  • Read one character with indexing (word[i]), including from the end with a negative index.
  • Take out part of a string with slicing (word[a:b]).
  • Convert between a character and its code point with ord() and chr().

Before this module

Lessons

  1. 1Strings

Practice

Try these on the judge. Each link opens the problem on DMOJ.

  1. 2015 J2
    Happy or Sad (opens on DMOJ in a new tab) DMOJ

    Count two kinds of faces in a line of text and decide whether it reads happy, sad, unsure, or neither.

    Why DMOJ: Tries the same kind of problem on DMOJ, which holds 2014 to 2020.

  2. 2019 J2
    Time to Decompress (opens on DMOJ in a new tab) DMOJ

    Turn each "count and character" line into that character repeated that many times.

    Why DMOJ: Tries the same kind of problem on DMOJ, which holds 2014 to 2020.

  3. 2018 J2
    Occupy parking (opens on DMOJ in a new tab) DMOJ

    Compare two lines and count where both mark the same spot.

    Why DMOJ: Tries the same kind of problem on DMOJ, which holds 2014 to 2020.