Want to count how often a substring occurs in a string? Or how many lines a
You can use a single argument (the substring to be counted), and two optional arguments start and end to indicate the first or the last index of the substring. This way, you can focus on a fixed area within your string.
Here is an example:
s = "Hi my name is, hi my name is, slim shady" print(s.count("name")) # 2 print(s.count("name", 10)) # 1
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.