print(abs(-4)) # 4
print(abs(-4.6)) # 4.6
print(abs(4)) # 4
print(abs(4.6)) # 4.6
Data type of the output is same as input number.
print(type(abs(-4))) # <class 'int'>
print(type(abs(-4.6))) # <class 'float'>
print(type(abs(4))) # <class 'int'>
print(type(abs(4.6))) # <class 'float'>
negative_float = -7.25
print(abs(negative_float)) # Output: 7.25
complex_num = 3 + 4j
print(abs(complex_num)) # Output: 5.0
numbers = [-1, 2, -3, 4, -5]
absolute_numbers = [abs(num) for num in numbers]
print(absolute_numbers) # Output: [1, 2, 3, 4, 5]
point1 = (3, 4)
point2 = (7, 1)
distance = abs(point2[0] - point1[0]) + abs(point2[1] - point1[1])
print(distance) # Output: 7
user_input = input('Enter a number: ')
number = float(user_input)
print('The absolute value is: ', abs(number))
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.