Python | функция math.fabs ()
Опубликовано: 9 Апреля, 2022
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.fabs()
function returns the absolute value of the number.
Syntax: math.fabs(x) Parameter: x: This is a numeric expression. Returns: the absolute value of the number.
Code #1:
# Python code to demonstrate the working of fabs() # importing "math" for mathematical operations import math x = - 33.7 # returning the fabs of 33.7 print ( "The fabs of 33.7 is : " , end = "") print (math.fabs(x)) |
Output:
The fabs of 33.7 is : 33.7
Code #2:
# Python code to demonstrate the working of fabs() # importing "math" for mathematical operations import math # prints the fabs using fabs() method print ( "math.fabs(-13.1) : " , math.fabs( - 13.1 )) print ( "math.fabs(101.96) : " , math.fabs( 101.96 )) |
Output:
math.fabs(-13.1) : 13.1 math.fabs(101.96) : 101.96
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.