Min menu

Pages

Python numbers functionabs ()

Python numbers  functionabs()

its definition

Returns the absolute value of the number we pass to the place of the parameter x.


built

                  abs(x)
	  

parameters

xA number that has no specific type.


Return value

Returns the absolute value of the number we pass to the place of the parameter x.


Example

Test.py
                    x = -5 # - its value is 5 x Here we have defined a variable named 
	  
		  print('x =', x) # as it is x Here we have shown the value of the variable 
		  print('abs(x) =', abs(x)) # abs( ) the absolute returned by the function x here we display the value of the variable
	

We will get the following result when running.

x = -5
abs(x) = 5

Python numbers  functionround()

its definition

Returns the closest integer to the number we pass to it in place of the parameter number.

Python numbers round () function Define it Returns the nearest integer to the number we pass to it in the place of the parameter number.

built

                  round(number[, ndigits])
	  

parameters

  • numberA number that has no specific type.

  • ndigitsThis is an optional parameter, i.e. you are not forced to pass the value in its place, which is an integer that represents at any number some comma you want the rounding to occurRounding.
    If you pass the value Noneor do not pass the value of the location of this parameter, it will be considered that you have passed the value 0 to it and therefore no number of some comma will be shown.


Return value

Returns the closest integer to the number that we pass to it in the place of the parameter x, returns it as float.


Example

Test.py
                    x = 5.674 # whose value is 5.674 x Here we have defined a variable named 
	  
		  print('round(',x,') =', round(x)) # x to return the closest value to the value of round() here we called the function 
		  print('round( ',x,', 1) =', round(x, 1)) # Ignoring any number after the comma with x to return the closest value to the value of the variable round() here we called the function 
		  print('round(',x, ', 2) =', round(x, 2)) # Ignoring any number after the comma with x to return the closest value to the value of the variable round() here we called the function 
		  print('round(',x,', 3) = ', round(x, 3)) # Ignoring any number after the comma with three x numbers to return the closest value to the value of the variable round() here we called the function
		  print('round(',x,', 4) =', round(x, 4)) # ignoring any number after the comma with four x numbers to return the closest value to the value of the variable round() here we called the function
	

We will get the following result when running.

round ( 5.674 ) = 6
round ( 5.674 , 1) = 5.7
round ( 5.674 , 2) = 5.67
round ( 5.674 , 3) ​​= 5.674
round ( 5.674 , 4) = 5.674

Python numbers  functionmax()

its definition

Returns the largest number of the set of numbers we pass to it asArguments.


built

                  # first form 
		max(iterable, *[, key, default]) 
	
		# second form 
		max(arg1, arg2, *args[, key])
  

parameters

This function can be called in two ways:

  • An array of numbers can be passed asArgumentWith its elements placed between []or ().

  • And any number of numbers can be passed to it asArgumentsWith a comma between each two numbers.


Return value

Returns the largest number of the set of numbers we pass to it asArguments.


first example

Test.py
                    # Here we have defined 3 variables with different values 
		  ​​x = 1 
		  y = 7 
		  z = 4 
	  
		  # max by function z and y ,x here we show the largest value among the values ​​in the variables 
		  print('The biggest number is:', max( x, y, z))
	

We will get the following result when running.

The biggest number is: 7

second example

Test.py
                    # (i.e. as a single object containing a set of values) iterable Here we have defined an array of numbers and put their values ​​inside [] so that it becomes as 
		  iterable = list([1, 4, 2, 9, 6, 5]) 
	  
		  # iterable Here we have shown the value The largest of the values ​​in the 
		  print('The biggest number is:', max(iterable))
	

We will get the following result when running.

The biggest number is: 9

Python numbers  functionmin()

its definition

Returns the smallest number of the set of numbers we pass to it asArguments.


built

                  # first form 
		min(iterable, *[, key, default]) 
	
		# second form 
		min(arg1, arg2, *args[, key])
  

parameters

This function can be called in two ways:

  • An array of numbers can be passed asArgumentWith its elements placed between []or ().

  • And any number of numbers can be passed to it asArgumentsWith a comma between each two numbers.


Return value

Returns the smallest number of the set of numbers we pass to it asArguments.


first example

Test.py
                    # Here we have defined 3 variables with different values 
		  ​​x = 7 
		  y = 1 
		  z = 4 
	  
		  # min by the function z and y ,x here we show the smallest value among the values ​​in the variables 
		  print('The smallest number is:', min( x, y, z))
	

We will get the following result when running.

The smallest number is: 1

second example

Test.py
                    # (i.e. as a single object containing a set of values) iterable Here we have defined an array of numbers and put their values ​​inside [] so that it becomes as 
		  iterable = list([1, 4, 2, 9, 6, 5]) 
	  
		  # iterable Here we have shown the value The smallest of the values ​​in the 
		  print('The smallest number is:', min(iterable))
	

We will get the following result when running.

The smallest number is: 1