Fancy String Methods

Let’s learn a few fun string methods. You don’t have to memorize them all; you can look up this page again if you forget them. I want to show you a small part of what strings can do. In fact, I can’t remember even half of the string methods myself—but that’s fine, because the Internet has great references with all of the string methods listed and explained. (I’ll show you where to find them in Chapter 15, Beyond This Book.) Actually, I don’t even want to know all the string methods. It’s kind of like knowing every word in the dictionary: I can speak English just fine without knowing every word in the dictionary.

The first string method is reverse, which returns a reversed version of the string:

1: var1 = ​"stop"

Get Learn to Program, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.