>>> n = -42
>>> -n # if you know n is negative
42
>>> abs(n) # for any n
42
Don’t forget to check the docs.
More Related Contents:
- How to add numbers inside a variable? [closed]
- How to generate random binary numbers 0 or 1 with length of N and with option to control the probability of having 0 or 1?
- Is there a way to ordinate numbers in a list?
- How to extract numbers from a string in Python?
- How to format a floating number to fixed width in Python
- Is there a way to convert number words to Integers?
- Python math is wrong [duplicate]
- python re.sub group: number after \number
- Why doesn’t this division work in Python? [duplicate]
- Grouping / clustering numbers in Python
- What is the most pythonic way to check if an object is a number?
- How to generate random numbers that are different? [duplicate]
- Checking odd/even numbers and changing outputs on number size
- Removing all non-numeric characters from string in Python
- How can I check if my python object is a number? [duplicate]
- Find the greatest number in a list of numbers
- How do you check in python whether a string contains only numbers?
- Loop until a specific user input [duplicate]
- Python floating-point math is wrong [duplicate]
- Generating non-repeating random numbers in Python
- Python: Number of the Week in a Month
- Python – Regular expressions get numbers between parenthesis
- Turn a single number into single digits Python [duplicate]
- Parse currency into numbers in Python
- Find the greatest (largest, maximum) number in a list of numbers
- Sending data from HTML form to a Python script in Flask
- SQLAlchemy: unexpected results when using `and` and `or`
- type object ‘datetime.datetime’ has no attribute ‘datetime’
- Can’t pickle defaultdict
- Python selenium keep browser open