Python Math – Python математик #

Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical tasks on numbers.

Python-д тоон дээр математик үйлдэл хийх боломжийг олгодог өөрийн өвөрмөц математик функцууд болон өргөн хүрээтэй math модуль байдаг.

Built-in Math Functions – Математик Функцууд #

The min() and max() functions can be used to find the lowest or highest value in an iterable:

min() болон max() функцууд нь хамгийн бага буюу хамгийн их утгыг давтаж олоход ашиглагддаг:

Example – Жишээ #

x = min(51025)
y = max(51025)
print(x)
print(y)

The abs() function returns the absolute (positive) value of the specified number:

abs() функц нь тодорхойлогдсон тооны абсолют (эерэг) утгыг буцаана:

Example – Жишээ #

x = abs(-7.25)
print(x)

The pow(xy) function returns the value of x to the power of y (xy).

pow(x, y) функц нь x-ийн y зэрэгт үйлдлийг гүйцэтгэж үр дүнг буцаана (xy).

Example – Жишээ #

Return the value of 4 to the power of 3 (same as 4 * 4 * 4):

4-ийн 3 зэргийг буцаана(4*4*4-тэй адилхан). 

x = pow(43)
print(x)

The Math Module – Math Модуль #

Python has also a built-in module called math, which extends the list of mathematical functions.

Python нь math хэмээх суурилсан модультай бөгөөд энэ нь математик функцуудын жагсаалтыг өргөжүүлдэг.

To use it, you must import the math module:

math модулийг ашиглахын тулд эхлээд түүнийг импортлох шаардлагатай:

import math

When you have imported the math module, you can start using methods and constants of the module.

math модулийг импортолсны дараа, та модулийн функцүүд болон тогтмол утгуудыг ашиглаж эхлэх боломжтой.

The math.sqrt() method for example, returns the square root of a number:

Жишээлбэл, math.sqrt() функц нь тооны квадрат язгуурыг буцаана:

Example – Жишээ #

import math
x = math.sqrt(64)
print(x)

The math.ceil() method rounds a number upwards to its nearest integer, and the math.floor() method rounds a number downwards to its nearest integer, and returns the result:

math.ceil() арга нь тоог дээш нь хамгийн ойрын бүхэл тоо хүртэл, харин math.floor() арга нь тоог доош нь хамгийн ойрын бүхэл тоо хүргэж, үр дүнг буцаана:

Example – Жишээ #

import math
x = math.ceil(1.4)
y = math.floor(1.4)
print(x) # returns 2
print(y) # returns 1

The math.pi constant, returns the value of PI (3.14…):

math.pi тогтмол утга нь PI (3.14…) утгыг буцаана:

Example – Жишээ #

import math
x = math.pi
print(x)

Python math Module – Python math Модуль #

Python has a built-in module that you can use for mathematical tasks.

Python нь математикийн үйлдлүүдэд ашиглах боломжтой модультай.

The math module has a set of methods and constants.

math модуль нь хэд хэдэн функцүүд болон тогтмол утгуудыг агуулдаг.


Math Methods – Математик Функцүүд #

Method

Функц

Description

Тайлбар

math.acos() Returns the arc cosine of a number

Тооны арк косинусыг буцаана.

math.acosh() Returns the inverse hyperbolic cosine of a number

Тооны эргүүлэх гиперболик косинусыг буцаана.

math.asin() Returns the arc sine of a number

Тооны арк синусыг буцаана.

math.asinh() Returns the inverse hyperbolic sine of a number

Тооны эргүүлэх гиперболик синусыг буцаана.

math.atan() Returns the arc tangent of a number in radians

Тооны арк тангенсийг радианаар буцаана.

math.atan2() Returns the arc tangent of y/x in radians

y/x-ийн арк тангенсийг радианаар буцаана.

math.atanh() Returns the inverse hyperbolic tangent of a number

Тооны эргүүлэх гиперболик тангенсийг буцаана.

math.ceil() Rounds a number up to the nearest integer

Тоог хамгийн ойрын бүхэл тоо руу дээшлүүлнэ.

math.comb() Returns the number of ways to choose k items from n items without repetition and order

n зүйлээс k зүйлийг давталт болон дараалалгүйгээр сонгох арга замуудын тоог буцаана.

math.copysign() Returns a float consisting of the value of the first parameter and the sign of the second parameter

Эхний параметрийн утгыг, хоёрдахь параметрийн тэмдэгтэйгээр буцаана.

math.cos() Returns the cosine of a number

Тооны косинусыг буцаана.

math.cosh() Returns the hyperbolic cosine of a number

Тооны гиперболик косинусыг буцаана.

math.degrees() Converts an angle from radians to degrees

Радиан өнцгийг градус руу хувиргана.

math.dist() Returns the Euclidean distance between two points (p and q), where p and q are the coordinates of that point

Хоёр цэгийн Евклидийн зайг буцаана (p ба q цэгүүдийн координатууд).

math.erf() Returns the error function of a number

Тооны алдаа функцийг буцаана.

math.erfc() Returns the complementary error function of a number

Тооны нэмэлт алдаа функцийг буцаана.

math.exp() Returns E raised to the power of x

e-ийн x зэрэгт үйлдлийг буцаана.

math.expm1() Returns Ex – 1

Ex – 1 үйлдлийг буцаана.

math.fabs() Returns the absolute value of a number

Тооны абсолют утгыг буцаана.

math.factorial() Returns the factorial of a number

Тооны факториалийг буцаана.

math.floor() Rounds a number down to the nearest integer

Тоог хамгийн ойрын бүхэл тоо руу доош нь бууруулна.

math.fmod() Returns the remainder of x/y

x/y үйлдлийн үлдэгдлийг буцаана.

math.frexp() Returns the mantissa and the exponent, of a specified number

Тухайн тооны мантисса болон зэргэмжийг буцаана.

math.fsum() Returns the sum of all items in any iterable (tuples, arrays, lists, etc.)

Давтах боломжтой бүх зүйлсийн нийлбэрийг буцаана (tuple, array, list, гэх мэт).

math.gamma() Returns the gamma function at x

Тооны гамма функцийг буцаана.

math.gcd() Returns the greatest common divisor of two integers

Хоёр бүхэл тооны хамгийн их ерөнхий хуваагчыг буцаана.

math.hypot() Returns the Euclidean norm

Евклидийн нормыг буцаана.

math.isclose() Checks whether two values are close to each other, or not

Хоёр утга ойрхон байгаа эсэхийг шалгана.

math.isfinite() Checks whether a number is finite or not

Тоог хязгаартай эсэхийг шалгана.

math.isinf() Checks whether a number is infinite or not

Тоог хязгааргүй эсэхийг шалгана.

math.isnan() Checks whether a value is NaN (not a number) or not

Утга NaN (тоо биш) эсэхийг шалгана.

math.isqrt() Rounds a square root number downwards to the nearest integer

Тооны язгуурыг доош бүхэллэж задална.

math.ldexp() Returns the inverse of math.frexp() which is x * (2**i) of the given numbers x and i

math.frexp()-ийн урвуу үйлдэл болох x * (2**i) үйлдлийг буцаана.

math.lgamma() Returns the log gamma value of x

Тооны лог гамма утгыг буцаана.

math.log() Returns the natural logarithm of a number, or the logarithm of number to base

Тооны натурал логарифмыг эсвэл тогтмол суурийн логарифмыг буцаана.

math.log10() Returns the base-10 logarithm of x

x-ийн суурь-10 логарифмыг буцаана.

math.log1p() Returns the natural logarithm of 1+x

1+x-ийн натурал логарифмыг буцаана.

math.log2() Returns the base-2 logarithm of x

x-ийн суурь-2 логарифмыг буцаана.

math.perm() Returns the number of ways to choose k items from n items with order and without repetition

x-ийн суурь-2 логарифмыг буцаана.

math.pow() Returns the value of x to the power of y

x-ийн y зэрэгт үйлдлийг буцаана.

math.prod() Returns the product of all the elements in an iterable

Давтах боломжтой бүх элементийн үржвэрийг буцаана.

math.radians() Converts a degree value into radians

Градус утгыг радиан руу хувиргана.

math.remainder() Returns the closest value that can make numerator completely divisible by the denominator

Бүрэн хуваагдах боломжтой хамгийн ойрын утгыг буцаана.

math.sin() Returns the sine of a number

Тооны синусыг буцаана.

math.sinh() Returns the hyperbolic sine of a number

Тооны гиперболик синусыг буцаана.

math.sqrt() Returns the square root of a number

Тооны квадрат язгуурыг буцаана.

math.tan() Returns the tangent of a number

Тооны тангенсийг буцаана.

math.tanh() Returns the hyperbolic tangent of a number

Тооны гиперболик тангенсийг буцаана.

math.trunc() Returns the truncated integer parts of a number

Тооны бүхэл хэсгийг таслах үйлдлийг буцаана.

Math Constants – Математик Тогтмол Утгууд #

Constant

Тогтмол

Description

Тайлбар

math.e Returns Euler’s number (2.7182…)

Эйлерийн тоог буцаана (2.7182…)

math.inf Returns a floating-point positive infinity

Цэгийн эерэг хязгаарыг буцаана.

math.nan Returns a floating-point NaN (Not a Number) value

Хөвөгч цэгийн NaN (Тоон биш) утгыг буцаана.

math.pi Returns PI (3.1415…)

Пи утгыг буцаана (3.1415…)

math.tau Returns tau (6.2831…)

Тау утгыг буцаана (6.2831…)

Powered by BetterDocs

Leave a Reply