Creating, Measuring, Indexing

A string is a sequence of characters in quotes. Because it's a sequence, every character has a numbered position, an index, starting from 0.

EXAMPLE
loading editor…
YOUR TURN
Your turn → Print the LAST letter using its index. (Python bonus: word[-1] counts from the end.)
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

String length

PYTHON

len(word)

JAVASCRIPT

word.length
Compare → Python uses a function you wrap around the string. JavaScript uses a property attached to the string. Same answer, different grammar, a pattern you'll see constantly.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Slicing and Concatenation →
← Back