import。math
时间: 2023-11-26 22:04:48 浏览: 63
The `math` module in Python provides various mathematical functions and constants. Some of the commonly used functions in the `math` module are:
- `math.sqrt(x)`: Returns the square root of x.
- `math.floor(x)`: Returns the largest integer less than or equal to x.
- `math.ceil(x)`: Returns the smallest integer greater than or equal to x.
- `math.pow(x, y)`: Returns x raised to the power y.
- `math.sin(x)`: Returns the sine of x in radians.
- `math.cos(x)`: Returns the cosine of x in radians.
- `math.tan(x)`: Returns the tangent of x in radians.
- `math.log(x, base)`: Returns the logarithm of x with base base.
Some of the commonly used constants in the `math` module are:
- `math.pi`: Returns the value of pi (3.141592653589793).
- `math.e`: Returns the value of e (2.718281828459045).
To use the `math` module in Python, you can import it using the `import` statement:
```python
import math
```
After importing the `math` module, you can use its functions and constants by prefixing them with `math.`. For example:
```python
import math
print(math.sqrt(16)) # Output: 4.0
print(math.floor(4.9)) # Output: 4
print(math.sin(math.pi/2)) # Output: 1.0
```
阅读全文