Skip to content

A new string method, .isnumber() #133318

@rxzzakcodes

Description

@rxzzakcodes

Feature or enhancement

Proposal:

A string method called .isnumber(), it will check if a string is a float or an integer and return True or False.

def isnumber(text)
    try:
        float(text)
        return True
    except ValueError:
        return False

Examples:

abc = "123"
pi = "3.14159"
hello = "hello"

print(isnumber(abc)) # True
print(isnumber(pi)) # True
print(isnumber(hello)) # False

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions