**Built-in:** The abs method is not part of the math module. Instead, you can use it directly in your programs.

**Zero:** The absolute value of zero is zero. This is well-known but good to test in a program.

**Version 1:** This version of the code uses the abs() method to compute the absolute value of a number.

**Version 2:** Here we use an inlined if-else statement to compute the absolute value.

**Result:** Using an if-else to compute the absolute value was faster. But the difference here is not relevant to many programs.

**And:** We can access elements in a list with positive values returned by abs. This can speed up programs.

Home

Dot Net Perls

© 2007-2020 Sam Allen. Every person is special and unique. Send bug reports to info@dotnetperls.com.