From the course: Python Standard Library Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Searching strings - Python Tutorial
From the course: Python Standard Library Essential Training
Searching strings
- [Man] Another really common scenario involves searching strings for specific data, and the python string object has several built in methods to help out with this. So the starts with and ends with functions can be used to see if a given string starts or ends with a specific sequence of characters, and let's try these out and some others by opening the search, underscore start file. As you can see I have a sample string here, and I can use the starts with and ends with functions to look for specific sub-strings. So I'll write print, samplestr dot starts with, and I'll see if it starts with the and then just for comparison I'm going to try the same thing but in this case I'll use a lower case t, and then I'll try one more, I'll use ends with and I'll write dog. Okay? So let's go ahead and run this, and I'll run it the same way I did the others with run python file in terminal. And you can see that the functions are case sensitive because the first example returns true with the capital…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.