You can create one by writing it: 123 is Ruby code and it represents the number one-hundred-twenty-three. Negative numbers are created by prepending a minus - : This is the number minus-ninety-nine: -99 . And of course there are decimal numbers, too. Again, you create one by writing it: 12.34 .
In Python, positive numbers can be changed to negative numbers with the help of the in-built method provided in the Python library called abs (). When abs () is used, it converts negative numbers to positive. However, when -abs () is used, then a positive number can be changed to a negative number.
To convert negative number to positive number (this is called absolute value), uses Math. abs(). This Math. abs() method is work like this “ number = (number < 0 ? -number : number); ".
Using abs
will return the absolute value of a number
-300.abs # 300
300.abs # 300
Put a negative sign in front of it.
>> --300
=> 300
>> x = -300
=> -300
>> -x
=> 300
Wouldn't it just be easier to multiply it by negative one?
x * -1
That way you can go back and forth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With