Modules in Python
Modules are files that contain Python code, which can be used to add functionality to your programs. To use a module in your program, you can use the import statement.
Here's an example of using the math module to calculate the square root of a number:
python
import math
x = 16
result = math.sqrt(x)
print(result)
In this example, we import the math module using the import statement. We then use the sqrt function from the math module to calculate the square root of the number 16. Finally, we print the result.
No comments:
Post a Comment