Get absolute value without using abs function nor if statement in Python1 min read

You can find the absolute value without using “ABS” with the simple method below.
First compute the square of the number. Then calculate the square root of the calculated value.

Example 1: Simple way

Example 2: Create your custom abs method.

Example 3: Alternative way.

Example 4: 


Leave a Comment