# How do I check if a string represents a number in Python?

To check if a string represents a number (float or int) in Python, you can try casting it to a float or int and check if the cast was successful. If the string can't be cast, then it is not a number.

Here is an example:

```python
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        return False

print(is_number('123'))  # True
print(is_number('123.456'))  # True
print(is_number('123a'))  # False
print(is_number('abc'))  # False
```

Alternatively, you can use the `isdigit` method of strings:

```python
def is_number(s):
    return s.isdigit()

print(is_number('123'))  # True
print(is_number('123.456'))  # False
print(is_number('123a'))  # False
print(is_number('abc'))  # False
```

Note that the `isdigit` method will only return `True` for strings that consist only of digits and that do not have a decimal point. It will return `False` for strings like `'123.456'` or `'123a'`.