Skip to main content

Module classify

Module classify 

Source
Expand description

The questions a string answers about itself.

Twelve methods on str whose names all start with is, asking eleven different questions, and the names do not make it obvious which. Three of them are here in name only, because their data lives with the thing it belongs to: isprintable is crate::printable, and the three case ones lean on crate::casing.

§The three number ones

isdecimal, isdigit and isnumeric sound like one question asked three ways and are three properties that nest. '٣' is all three, being an Arabic-Indic three you could write a number with. '³' is a digit and a number and not a decimal, because a superscript is not a position in a numeral. '½' is only a number. So int() takes the first group, and a runtime that answered char::is_numeric to all three would be wrong twice.

§Empty

Most of these are false for the empty string, on the grounds that a claim about every character is worth nothing when there are none. isascii and isprintable are true for it instead, because those are claims about what the string does not contain. That split is CPython’s and is not a rule you could guess, so it is written down here and pinned by a test.

Functions§

is_alnum
str.isalnum, which is the union of the other four and not a property of its own.
is_alpha
str.isalpha.
is_ascii
str.isascii, which is true of the empty string because it is a claim about what is not there.
is_decimal
str.isdecimal, the narrowest of the three number questions.
is_digit
str.isdigit.
is_identifier
str.isidentifier.
is_lower
str.islower.
is_numeric
str.isnumeric, the widest.
is_printable_str
str.isprintable, true of the empty string for the same reason.
is_space
str.isspace.
is_space_point
Whether a single code point is whitespace, which is also what a split with no separator splits on and what a strip with no argument takes off.
is_title
str.istitle.
is_upper
str.isupper.