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.

isalpha in Python: String Letter Check

isalpha in Python: String Letter Check

When you check whether a text value contains only letters, you need a clear rule for every character in it. Python’s isalpha() method returns True when a nonempty string consists entirely of Unicode letters. This article shows how to call…

Python String isalnum() Function

Python String isalnum() Function

Choosing a test for a Python string starts with deciding which characters it may contain. Python’s str.isalnum() returns True when a nonempty string contains only alphabetic or numeric characters. I’ll show how to test a complete string with str.isalnum() and…

Remove Spaces in String Python

Remove Spaces in String Python

Removing spaces from a Python string means choosing which spaces or whitespace characters to change. Python string methods change selected whitespace in a string. The example shows the output for removing ordinary spaces and for removing all whitespace. TL;DR Use…

Python str.upper() Method: Syntax and Examples

Python str.upper() Method: Syntax and Examples

Converting a Python string to uppercase gives it an uppercase form. Python’s str.upper() method returns a copy of a string with its cased characters converted to uppercase. I’ll show how to call str.upper() and what happens to the original string…

Convert a Tuple to a String in Python

Convert a Tuple to a String in Python

A tuple can hold values that need to appear as text in a log or output field. Python’s join() method combines string values with a separator, while str() turns a tuple into its Python-style representation, including punctuation. I’ll show how…

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…