Built-in String Functions

Strings have methods that you can call on them. However, there are also built-in functions that are relevant to strings. A few that we'll use include:

The Built-In len() Function

len is a built-in function that returns the length of a sequence

s = "cat"

#  returns 3
print(len(s))

Index of the Last Character in a String

What's the formula for getting the last character in a string?

length of string - 1

Index of the Last Character in a String Continued

What values / expressions would you use if you wanted to index into the string below to get the last character?

s = "cat"
print(s[?])
print(s[2])
print(s[-1])
print(s[len(s) - 1])

Representing Strings

There's a standard for consistently representing text through different character sets and encodings.

Unicode Table

Let's see that table again.

chr() and ord()

Python has a couple of functions that translate code points to characters and characters back to code points.