If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Python में mathematical operations perform करने के लिए कई built इन functions भी हैं जैसे -
min(), max() functions का use किसी भी iterable data type (like : list , tuple , set) में minimum और maximum value को return करता है।
print('Maximum in list :', max([12,4,5,66,76,78])) #find max in list.
print('Maximum in tuple :', max((2,4,5,66,76,78))) #find max in tuple.
print('Minimum in set :', min({34,56,45,56,34,32,4})) #find min in set.
print('Minimum in list :', min({23,45,3,44.5, -2,43})) #find min in list.
C:\Users\Rahulkumar\Desktop\python>python min_max.py Maximum in list : 78 Maximum in tuple : 78 Minimum in set : 4 Minimum in list : -2
pow(x, y) function का use x to the power of y (xy) की value return करता है। हालाँकि उसके लिए आप x**y का use भी कर सकते हैं। दोनों का output same ही होगा।
For Example -
# both are same.
print(pow(2, 3))
print(2**3)
Output :
8
8
abs() function किसी value की absolute positive value return करता है।
Example -
print(abs(-23.4))
print(abs(-23))
Output :
23.4
23
Python में mathematical tasks perform करने के लिए math module भी provide किया है जिसमे कई functions define हैं जिनका use आप अपनी need के according कर सकते हैं।
Function Name | Description |
---|---|
cos() | Returns the cosine of a number |
cosh() | Returns the hyperbolic cosine of a number |
degrees() | Converts an angle from radians to degrees |
fabs() | Returns the absolute value of a number |
factorial() | Returns the factorial of a number |
floor() | Rounds a number down to the nearest integer. |
ceil() | Rounds a number up to the nearest integer. |
gcd() | Returns the greatest common divisor of two integers |
isqrt() | Rounds a square root number downwards to the nearest integer |
log() | Returns the natural logarithm of a number, or the logarithm of number to base |
log10() | Returns the base-10 logarithm of x |
pow() | Returns the value of x to the power of y |
prod() | Returns the product of all the elements in an iterable(like : list , tuple , set) |
radians() | Converts a degree value into radians |
sin() | Returns the sine of a number |
sinh() | Returns the hyperbolic sine of a number |
sqrt() | Returns the square root of a number |
tan() | Returns the tangent of a number |
# first import math module.
import math
print('Square root of 81 :', math.sqrt(81))
print('Factorial of 6 :', math.factorial(6))
print(math.ceil(3.4))
print(math.floor(3.4))
print('Absolute Value :', math.fabs(-3.5))
print('sin90 :', math.sin(90))
print('cos30 :', math.cos(30))
print('tan45 :', math.tan(45))
C:\Users\Rahulkumar\Desktop\python>python math_functions.py Square root of 81 : 9.0 Factorial of 6 : 720 4 3 Absolute Value : 3.5 sin90 : 0.8939966636005579 cos30 : 0.15425144988758405 tan45 : 1.6197751905438615
इसके अलावा math module में कुछ constants भी हैं, मतलब वो mathematics variables जिनकी values पहले से fixed हैं आप उन्हें change नहीं कर सकते हैं।
# first import math module.
import math
print('PI value :', math.pi)
print('TAU value :', math.tau)
print('NAN value :', math.nan)
print('INF value :', math.inf)
print('E value :', math.e)
C:\Users\Rahulkumar\Desktop\python>python math_constants.py PI value : 3.141592653589793 TAU value : 6.283185307179586 NAN value : nan INF value : inf E value : 2.718281828459045
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook