Skip to main content

Posts

Featured

Exploring the endswith() method

Exploring the endswith() method Today I learned about the .endswith() method in Python. It was something really really cool and new and it was really interesting to use. It basically is a really really cool way to check if a string ends with the same thing it is being checked against or not. So how would we use it exactly? Well it takes 3 arguments: one compulsory, two optional: string.endswith(suffix[, start [, end]]) So you can either just have the suffix and see if the value is the same at the end of the string: name_string = "susanna" name_string.endswith("anna") -> returns True Or you can slice, let me try name_string = "susanna" name_string.endswith("san", 2, 5) -> returns True As with all slicing, please remember that the ending condition is +1 of the index of the last character you would like to include, and the start INCLUDES the starting character that you want to include, so the exact index of that character. It's just like

Latest posts

Breaking Down Problems Into Ever Smaller Parts, Smaller and Smaller

A Protocol for Raising PRs

Identity vs. Equality: When to use "is/is not" versus equality operators "==/!=" in Python

Reflections on how much I wanted to be a software engineer...

Today I Learned - HTTP Codes, PyTest and Testing HTTP Post Requests using Django

One of the coolest things: .translate() and str.maketrans() in Python

A Poem About Healing And Software Engineering

"The Beauty of Code Is To Express Meaning In A Way That Involves Elegant Abstractions That Are Simple To Understand": Understanding Interfaces

Using Decorators in Django

Handling Leap Years: Relativedelta