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.