Datatype of non-negative values

D

Dirk Hagemann

Hi,

Is there a datatype in python which allows no negative values? I
subtract several times something from a value and I don't want to chek
everytime if this value is still bigger or equal 0.

Thanks for help!
Dirk Hagemann
 
L

Larry Bates

What exactly do you want to happen when result
would be negative? I'll guess be zero:

pseudocode:

x=value
x=max(x-something, 0)

That way if it goes negative, it sticks to zero.

Larry Bates
 
D

Dirk Hagemann

A result smaller than 0 should be just invalid.

I'd like to work with "try" and "except" like this:
value=20
try:
value=value-23
except:
print 'value is smaller than 23'

Now it should run into the "except".

Dirk Hagemann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top