Category Python String

Strings – you use it in every program, just like any other programming language. Learn about Strings in Python and how to manipulate them in the Pythonic way.

How to Get a Substring in Python

How to Get a Substring in Python

`”banana”.find(“pear”)` returns `-1` when the text is absent. I’m fascinated that a failed search has a clear result, while `-1` can still act as a valid slice position. You can separate the idea of a text fragment from the operation…

Python replace() function

Python replace() function

Calling `”Python python PYTHON”.replace(“python”, “Ruby”)` changes only the lowercase match. I appreciate the `count` argument because it caps how many matches change. Pass the old and new text to `str.replace()` and check the returned string. Compare that returned string with…

Understanding Python f-string

Understanding Python f-string

Debug prints all repeat the same chore, because the variable name gets typed once as a label and once as the value. The f-string shorthand prints both from a single expression, so the label can never drift out of sync…

Python String join() function

Python String join() function

Every list of strings eventually needs to become one string, and the line that does it reads backwards. The separator calls the method while the list supplies the items, so a comma-joined row comes out as a one-liner once you…

What does {:02d} mean in Python?

What does {:02d} mean in Python?

String formatting is a very essential element of Python programming. Usually, we get strings that are not completely in the format that we want them to be in. Converting the string in the desired format is called string formatting. To…