TriskelionKal TriskelionKal - 1 year ago 108
Python Question

Detect whether a Python string is a number or a letter

How can I detect either numbers or letters in a string? I am aware you use the ASCII codes, but what functions take advantage of them?

Answer Source

You may use str.isdigit() and str.isalpha() to find this.

Sample Results:

# For alphabet
>>> 'A'.isdigit()
>>> 'A'.isalpha()

# For digit
>>> '1'.isdigit()
>>> '1'.isalpha()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download