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.

Translate String Python

Translate String Python

Several characters in a Python string may need different changes before the text is used elsewhere. str.translate() applies a table of character rules and returns a new string. This article shows how to build that table with str.maketrans() and when…

Decode String Python: Encode Bytes as Text

Decode String Python: Encode and Decode Bytes

Converting Python bytes to text starts with identifying the encoding that produced them. Python’s decode() method interprets bytes as text, while encode() turns text into bytes. This article shows how to encode a string and decode bytes with a matching…

Python String isnumeric() Method

Python String isnumeric() Method

When a Python program receives text that may contain numeric characters, you can check those characters before choosing how to handle the value. The str.isnumeric() method reports whether a non-empty string consists entirely of Unicode numeric characters, but it does…

Python String endswith() Function

Python String endswith() Function

A text value may need to match one expected ending or one of several alternatives. Python’s str.endswith() method checks whether a string ends with the supplied suffix and returns True or False. This article explains how to pass several suffixes…

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…