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 Split a String in Python

How to Split a String in Python

To turn a sentence into separate words, you can split its text at whitespace. Python’s str.split() returns the pieces as a list of strings and can also use a separator you specify. I’ll show how to choose a separator and…

Python String islower() Function

lower function in Python: Use str.lower()

Working with letter case in Python can mean changing text or checking how it is already cased. The str.lower() method returns a lowercase copy of a string, while islower() reports whether its cased characters are lowercase. I’ll show how to…

Python isdigit: Check Unicode Digits in Strings

Python isdigit: Check Unicode Digits in Strings

Checking whether a string contains digit characters is different from checking whether Python can parse it as an integer. Python’s str.isdigit() method tests whether every character in a non-empty string is a qualifying Unicode digit. I’ll show how to use…

Python String Template: How to Use It

String Template Python: Using Template Strings

When the same wording needs different values, Python’s string.Template lets you fill named fields from a mapping or keyword arguments. It replaces dollar-sign placeholders with the values you provide. This article shows how to create a template and choose between…

String Comparison Python: Equality and Order

String Comparison Python: Equality and Order

To compare text in Python, first choose the question your program needs answered. String comparison evaluates a relationship between text values and returns a Boolean result. This article shows how to test exact equality and check whether a string starts…

How to Check a Substring in Python

How to Check a Substring in Python

A text search can start by checking whether one string occurs within another. In Python, the in operator tests for that substring and returns True or False. This article explains how to check membership and how find() and index() behave…