KennisbankExamencentrum
NL · NLNederlands (Nederland)
Taal kiezen13

CKTIS / Python

str.isdigit

Test of niet-lege tekst uitsluitend Unicode-cijfers bevat. ² is een cijfer maar geen decimaal cijfer: isdigit geeft True en isdecimal False.

Versie: Python 3.14; repository image, production runtime not attested

Syntax

s.isdigit()

Test of niet-lege tekst uitsluitend Unicode-cijfers bevat. ² is een cijfer maar geen decimaal cijfer: isdigit geeft True en isdecimal False.

Een positieve test garandeert dus geen geldige invoer voor int.

assert "²".isdigit() and not "²".isdecimal() and not "".isdigit()

Voorbeelden

print("²".isdigit())
print("²".isdecimal())

Resultaat

True
False

Een positieve test garandeert dus geen geldige invoer voor int.

Bronnen