Is this what you want?

def check_negative(s):
    try:
        f = float(s)
        if (f < 0):
            return True
        # Otherwise return false
        return False
    except ValueError:
        return False

Not entirely sure if this is what you want though, maybe you should see ᴡʜᴀᴄᴋᴀᴍᴀᴅᴏᴏᴅʟᴇ3000's answer

Answer from heo on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-check-whether-a-number-is-positive-or-negative-or-zero
Python Program to Check Whether a Number is Positive or Negative or zero - GeeksforGeeks
July 15, 2025 - # Python program to check whether # the number is positive, negative # or equal to zero def check(n): # if the number is positive if n > 0: print("Positive") # if the number is negative elif n < 0: print("Negative") # if the number is equal ...
Discussions

python - Having trouble with 'and' 'or' statements and negative numbers - Geographic Information Systems Stack Exchange
When the negative number is returned ... to check if the cell is already occupied. This leads to other valid data being overwritten. I'm not sure whether this is a result of the way I have set up my 'and'/'or' operators or whether I modify the way I use negative numbers in python... More on gis.stackexchange.com
🌐 gis.stackexchange.com
September 26, 2014
Handling negative number inputs from the user
I would recommend you use a try instead. answer = input(f"What is {a} + {b}") try: answer = int(answer) except ValueError: print("That's not a number") More on reddit.com
🌐 r/learnpython
19
4
January 29, 2025
How do I check to see if multiple numbers are negative at once.
How are you receiving the data? Is it in a list (array)? A dictionary? The data structure will often answer the rest. Check out the methods available to those data structures. For an array, a simple for loop can iterate over a list and check if a number is negative. heck, there's probably even a standard .method that checks if something isNegative. More on reddit.com
🌐 r/learnpython
21
1
January 29, 2025
Can someone help me with this problem?
You have to remove: if top_of_range.isdigit(): top_of_range = int(top_of_range) And write: top_of_range = int(input("Type a number: ")) Edit: You take the first input number as a string, then the code checks if it is an integer, if it is an integer, it will then cast the integer into an integer - which doesn't make much sense. You could change it to check if it is a string instead though, if you want to keep those lines. The code have a bunch of other oddities, like the quit statements after every if-else, why are those there? More on reddit.com
🌐 r/learnpython
8
1
December 26, 2022
🌐
Reddit
reddit.com › r/learnpython › handling negative number inputs from the user
r/learnpython on Reddit: Handling negative number inputs from the user
January 29, 2025 -

This is a solution post. I had a problem and none of the solutions I found online were right for me. I eventually figured it out, and so I'm putting my solution here for future learners. Also if my solution is bad, I'll get some feedback. If you think it's obvious, then you're very clever, but no need to go to the trouble of letting me know!

I'm making an arithmetic game for my little one. So it had a line:

answer = int(input(f"What is {a} + {b}?"))

but of course he accidentally typed a letter and crashed the program. I wanted to handle this eventuality so I changed it to:

answer = input(f"What is {a} + {b}")
if answer.isnumeric():
    answer = int(answer)
else:
    print("That's not a number")
    continue

the trouble is I also have subtraction questions and negative numbers! But "-1".isnumeric()==False !!

So I started googling: "isnumeric negative numbers" and "parsing negative numbers" and so on. The solutions I found were quite convoluted, mostly they seemed to be worrying about SQL injection and used concepts I hadn't learned yet. I wanted a solution that only used the beginner stuff I already knew. I realised that I only had to check if the first symbol is "-" and the rest is numeric. So:

if answer.isnumeric() or answer[0]=="-" and answer[1:].isnumeric():

is the solution!

EDIT: There was a typo in my solution, I meant to check if everything after the initial "-" is numeric. Otherwise an answer like "-3e" gets through. Thanks to u/Rizzityrekt28 for the catch

🌐
Nextjournal
nextjournal.com › avidrucker › detecting-valid-number-strings-in-python
Detecting Valid Number Strings in Python - Nextjournal
... 1. is-valid-number? does the ... that only appears at the beginning of the string? 2. is-negative-number? does the string start with a hyphen (-)? If yes, it's a negative number....
🌐
Pierian Training
pieriantraining.com › home › how to check if a number is negative in python: a beginner’s guide
How to Check if a Number is Negative in Python: A Beginner's Guide - Pierian Training
June 18, 2023 - In conclusion, checking if a number is negative in Python is a simple task that can be accomplished using the comparison operator “<“. By comparing the number to 0, we can determine if it is negative or not.
🌐
Programiz
programiz.com › python-programming › examples › positive-negative-zero
Python Program to Check if a Number is Positive, Negative or 0
To understand this example, you should have the knowledge of the following Python programming topics: ... num = float(input("Enter a number: ")) if num > 0: print("Positive number") elif num == 0: print("Zero") else: print("Negative number")
🌐
GeeksforGeeks
geeksforgeeks.org › python › working-with-negative-numbers-in-python
Working with Negative Numbers in Python - GeeksforGeeks
July 23, 2025 - This method is useful when you need to work with the magnitude of a negative number. Python3 · # Example of using abs() function negative_number = -8 absolute_value = abs(negative_number) print("Absolute Value:", absolute_value) Output · Absolute Value: 8 · Using conditional statements allows you to check if a number is negative and take specific actions accordingly.
Find elsewhere
🌐
Quora
quora.com › What-method-checks-that-the-string-is-a-number-and-includes-negative-in-the-Python-language
What method checks that the string is a number and includes negative in the Python language? - Quora
Answer (1 of 8): The simplest way - use the inbuilt ‘int(..)’ function and capture the exception that int(..) raises when it finds something that isn’t an int (it raises a ValueError exception). Use try/except to capture whether a call to int() raises a ValueError.
🌐
CodeChef
codechef.com › learn › course › python-development › PYDEV04 › problems › PYTHPROB159
Check if a number is positive or negative in Python for project building
Test your Learn Python for project building knowledge with our Check if a number is positive or negative practice problem. Dive into the world of python-development challenges at CodeChef.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Sign Function in Python: sign/signum/sgn, copysign | note.nkmk.me
August 22, 2023 - If you need such a function, you could use numpy.sign() from NumPy or define your own function. ... The sign function returns 1 for positive numbers, -1 for negative numbers, and 0 for zero. You can get the sign of a number using this function.
🌐
Educative
educative.io › answers › how-to-remove-negative-numbers-from-a-list-in-python
How to remove negative numbers from a list in Python
We use a for loop to iterate over the list and execute the code in it that is to be applied to every element of the list. In this case, we check if the element is greater than 0 and add it to the new list using append(). ... Lines 2–4: Create a list that contains negative and positive values and print it.
🌐
W3Schools
w3schools.com › java › java_howto_pos_or_neg.asp
Java How To Find Out if a Number is Positive or Negative
Explanation: We use simple comparisons with > and <. - If the number is greater than 0, it is positive. - If the number is less than 0, it is negative.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.negative.html
numpy.negative — NumPy v2.3 Manual
numpy.negative(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'negative'>#
🌐
LearnDataSci
learndatasci.com › solutions › python-absolute-value
Python Absolute Value – abs() for real and complex numbers – LearnDataSci
The use of the abs() function has converted the negative numbers into positive ones. For the positive numbers, there has been no change. Remember that the absolute value of a real number refers to its distance from 0 and is known as magnitude.
🌐
Datamentor
datamentor.io › r-programming › examples › positive-negative-zero
Check if a Number is Positive, Negative or Zero
We check this in the expression of if. If it is FALSE, the number will either be zero or negative.
🌐
Real Python
realpython.com › python-range
Python range(): Represent Numerical Ranges – Real Python
September 9, 2025 - As always, the end value isn’t included in the range. You can still calculate the number of elements by looking at the difference of the arguments. Just keep track of the negative signs: (-3) - (-7) = 4. You can use any integer as a value for the first two arguments. However, many choices will lead to empty ranges. In particular, if the arguments are equal, then you know that the corresponding range will have zero elements.
🌐
W3Schools
w3schools.com › python › python_numbers.asp
Python Numbers
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
🌐
YouTube
youtube.com › programsandme
Python Program to Check Whether a Number is Positive, Negative, or Zero - YouTube
In this tutorial, we will learn how to write a Python program to check whether a number entered by the user is positive, negative, or zero. The input for thi...
Published: July 1, 2020
Views: 26K
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to check if a number is negative in python
5 Best Ways to Check if a Number is Negative in Python - Be on the Right Side of Change
February 16, 2024 - A conditional expression after an if statement checks if the number satisfies a condition—in this case, being negative—and returns the corresponding result. ... This snippet assigns the string “Negative” to result if num is negative, otherwise “Non-negative”. It is a useful and compact way to express the check and act on the result in the same line of code. Python’s math module provides a function copysign() that can be used to check the sign of a number.