Lecture

Key Python Built-in Modules

In programming, a library is a collection of pre-written code that offers reusable functionalities.

A library is composed of various modules, which can work together to perform specific tasks.

Python includes standard libraries such as math and datetime, and the built-in modules within these libraries are provided with Python's installation.

These built-in modules can be used instantly without any additional installation process.


Key Python Built-in Modules

  1. math

    • Provides functions for mathematical operations.

    • Examples: math.sqrt(), math.pi, math.sin()

  2. datetime

    • Handles dates and times.

    • Examples: datetime.datetime.now(), datetime.timedelta()

  3. os

    • Interacts with the operating system and handles the file system.

    • Examples: os.listdir(), os.path.join()

  4. sys

    • Interacts with the Python interpreter (a program that executes code).

    • Examples: sys.argv, sys.exit()

  5. random

    • Provides functions for generating random numbers.

    • Examples: random.randint(), random.choice()

  6. json

    • Parses and generates JSON data.

    • Examples: json.loads(), json.dumps()

  7. re

    • Handles strings using regular expressions.

    • Examples: re.match(), re.search()

  8. urllib

    • Used for handling URLs and sending HTTP requests.

    • Example: urllib.request.urlopen()


Built-in Module Usage Example

Example of Using the math Module
import math # Calculate the area of a circle radius = 5 area = math.pi * math.pow(radius, 2) print(f"Area of the circle: {area}")

Practice

Click the Run Code button on the right side of the screen to see the result or modify the code!

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help