Metode isdigit

Die metode isdigit toets of 'n string slegs uit syfers bestaan. Niks word as parameters aan die metode oorgedra nie. Die metode gee booleaanse waardes True of False terug.

Sintaksis

pythonstring.isdigit()

Voorbeeld

Kom ons toets of 'n string slegs uit syfers bestaan:

pythontxt = '12345'
print(txt.isdigit())

Resultaat van die kode-uitvoering:

pythonTrue

Voorbeeld

Laat daar nou ander karakters in die string wees:

pythontxt = '12345ab'
print(txt.isdigit())

Resultaat van die kode-uitvoering:

pythonFalse

Sien ook

  • metode isnumeric,
    wat toets of 'n string slegs getalle bevat
  • metode isspace,
    wat toets of 'n string slegs spasies bevat
  • metode isalnum,
    wat toets of 'n string slegs letters en syfers bevat
  • metode isalpha,
    wat toets of 'n string slegs letters bevat