程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Mathematical functions of Python built-in functions ---abs()

編輯:Python

1. Python Built in functions will be assembled into <builtin> Built in module , have access to list(__builtin__.__dict__) perhaps dir(__builtin__) To list all built-in functions , as follows :

Starting today , Learn to use these basic built-in functions , And make records , Enhance learning outcomes .

2. Start with mathematical functions

Python The built-in mathematical functions in realize the basic mathematical operations , Through these functions, data results can be obtained easily and quickly , If you want to implement more complex operations, you can use import Python Third party modules .

Let's introduce the first function of the mathematical function abs() function

abs() function : Get absolute value , Use this function to return the absolute value of a given value , Such as abs(x), return x The absolute value of

give an example 1: Get the absolute value of the number in the list

x_list = [2.8, 3, 0.5, -12, -3.5]
for num in x_list:
print(abs(num))

Running results :

 2.8
3
0.5
12
3.5

give an example 2: Define functions to output 2 The absolute value of multiplying numbers

def calcAbs(value1, value2):
return abs(value1 * value2)

Call the defined function and pass parameters , as follows :

print(calcAbs(2.5, 4.3)) # Output results :10.75
print(calcAbs(2.5, -4.3)) # Output results :10.75

abs Function is the most basic function in mathematical function , It's easy to use , You can use this function directly when you need to find the absolute value .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved