Data Science Explorer

[Basic Grammar] Python Math 본문

Python

[Basic Grammar] Python Math

grace21110 2023. 11. 24. 09:02
반응형
  • Built-In Math Functions 

The min() and max() functions can be used to find the lowest or highest value.


Example 

x = min (3,10, 1)
y = max (3,10, 1)

print(x)
print(y)

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

Example

x = abs(-8.25)

print(x)

 

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

Example 

Return the value of 4 to the power of 2. 

x = pow(4, 2)

print(x)

 

  • The Math Module 

The module called math extends the list of math functions. 

 

Example 

import math 

x = math.sqrt(3)
print(x)

The math.ceil() rounds a number upwards to its nearest integer and math.floor() rounds a number downwards to its nearest integer.

 

Example

import math

x = math.ceil(1.2)
y = math.floor(1.2)

print(x) # returns 2
print(y) # returns 1

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

 

Example 

import math

x = math.pi

print(x)

'Python' 카테고리의 다른 글

[Exercise] Functions  (0) 2024.04.05
[Basic Grammar] Datetime  (0) 2023.11.23
[Basic Grammar] Modules  (1) 2023.11.22
[Basic Grammar] Python Inheritance  (0) 2023.11.21
[Basic Grammar] Python Classes/Objects  (1) 2023.11.19