Python built-in functions

Source: Internet
Author: User
Tags abs natural logarithm ord pow random shuffle shuffle

#数学相关的函数#module for importing mathematicsImportMath#Floor () rounding downresult = Math.floor (6.2)Print(Result)#ceil () rounding upresult = Math.ceil (5.5)Print(Result)#round () Rounding Note: Not a function in math, the system comes with#N.5 when n is an odd number and an even number is placedresult = Round (8,5)Print(Result)#POW () calculates a number of n-th squareresult = Math.pow (5,3)Print(Result) result= 5 * * 3Print(Result)#sqrt () Open square operationresult = MATH.SQRT (5)Print(Result)#ABS () calculates the absolute value of a numeric system built-in function (original value type)result = ABS (-12)Print(Result)#MODF () splits a floating-point number into integers and decimals 2 (tuple type)result = MATH.MODF (12.5)Print(Result)#copysign () assigns a positive negative value of the second number to the first digitresult = Math.copysign (12,-5)Print(Result)#Fsum calculates the and (floating-point number) of numbers in a sequenceListvar = [4,5,3,7,2,5,6]result=math.fsum (Listvar)Print(Result)#sum () computes the sum of the numbers in a sequence (as determined by the data contents)Listvar = [4,5,3,7,2,5,6]result=sum (listvar)Print(Result)#Max () gets the maximum value in the sequenceNums = [3,5,6,0,9,34,56,32,67]result=Max (nums)Print(Result)#Max () returns the maximum value in multiple dataresult = Max (23,4,56,21,34,62,8,16)Print(Result)#min () gets the minimum value in the sequenceresult =min (nums)Print(Result)#min () returns the minimum value in multiple dataresult = Min (23,4,56,21,34,62,8,16)Print(Result)#Range () produces an integer within the range (generator) Note: Contains the start does not contain the endresult = Range (1,15)Print(Result) forIinchResult:Print(i)#values commonly used in the math module#pi πPrint(Math.PI)#e natural logarithmPrint(MATH.E)#随机数模块ImportRandom#random () randomly gets the decimal between 0~1 (contains 0 but not 1)result =random.random ()Print(Result)#choice () randomly returns a value in a sequenceListvar = [4,5,6,3,8,2,9,'C','D','A','X']result=Random.choice (Listvar)Print(Result)#Shuffle () random Shuffle listListvar = ['MF','SL','YJ','LSS','CYY']Print(Listvar) random.shuffle (Listvar)Print(Listvar)#Randrange () Gets the number of random integers in the developed rangeresult = Random.randrange (3,8,5)Print(Result)#uniform () gets a random number in the set rangeresult = Random.uniform (2,8)Print(Result)#进制相关#Hex () converts 10 binary to 16 binaryvar = 15result=Hex (Var)Print(Result,type (result))#Oct () converts 10 binary to 8 binaryvar = 46result=Oct (VAR)Print(Result,type (result))#bin () converts 10 binary to 2 binaryvar = 38result=bin (Var)Print(Result,type (result))#ASCII" "ASCII American Standard Information Interchange code 0-9, 48-57a-z, 65-90a-z, 97-122" "#Ord () gets the corresponding ASCII code according to the characterresult = Ord ('a')Print(Result)#Chr () gets the corresponding character according to the ASCII coderesult = Chr (80)Print(Result)#repr () output string as-is (without escaping the escape character, except the quotation marks)var ='if life \ ' cheat ' You don't be sad don't be impatient'Print(Var) result=Repr (Var)Print(Result)#Eval () executes the Python string as Python code. Use with cautionnum = 99var='num + 1'Num=Eval (Var)Print(num)

Python built-in functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.