0% found this document useful (0 votes)
3 views6 pages

Python Important Imports

The document lists the top 20 important Python modules along with their descriptions, important methods, and examples of usage. Each module, such as os, sys, and math, serves specific functionalities ranging from operating system interactions to data manipulation. This serves as a quick reference guide for Python developers to understand and utilize essential libraries.

Uploaded by

himanshuso388
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Python Important Imports

The document lists the top 20 important Python modules along with their descriptions, important methods, and examples of usage. Each module, such as os, sys, and math, serves specific functionalities ranging from operating system interactions to data manipulation. This serves as a quick reference guide for Python developers to understand and utilize essential libraries.

Uploaded by

himanshuso388
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Top 20 Most Important Python Imports

with Examples

Module: os

Description: Provides a way of using operating system dependent functionality.

Important Methods: getcwd, listdir, mkdir

Example:

import os
print(os.getcwd())

Module: sys

Description: Provides access to some variables used or maintained by the interpreter.

Important Methods: argv, exit, path

Example:

import sys
print(sys.argv)

Module: math

Description: Provides access to mathematical functions.

Important Methods: sqrt, pow, ceil

Example:

import math
print(math.sqrt(16))

Module: random
Description: Implements pseudo-random number generators.

Important Methods: randint, choice, shuffle

Example:

import random
print(random.randint(1, 10))

Module: datetime

Description: Supplies classes for manipulating dates and times.

Important Methods: datetime.now, date.today

Example:

from datetime import datetime


print(datetime.now())

Module: time

Description: Provides various time-related functions.

Important Methods: sleep, time

Example:

import time
time.sleep(1)
print("Slept for 1 second")

Module: json

Description: Provides methods for parsing JSON.

Important Methods: load, dump

Example:

import json
print(json.dumps({'name': 'Alice'}))
Module: re

Description: Provides regular expression matching operations.

Important Methods: search, match, findall

Example:

import re
print(re.findall(r'\d+', 'My number is 12345'))

Module: collections

Description: Implements specialized container datatypes.

Important Methods: Counter, defaultdict, deque

Example:

from collections import Counter


print(Counter('hello'))

Module: itertools

Description: Implements iterator building blocks.

Important Methods: count, cycle, combinations

Example:

import itertools
print(list(itertools.combinations([1, 2, 3], 2)))

Module: functools

Description: Higher-order functions and operations on callable objects.

Important Methods: reduce, lru_cache

Example:
from functools import reduce
print(reduce(lambda x, y: x+y, [1, 2, 3, 4]))

Module: operator

Description: Standard operators as functions.

Important Methods: itemgetter, attrgetter

Example:

import operator
print(operator.add(3, 5))

Module: pathlib

Description: Object-oriented filesystem paths.

Important Methods: Path, exists

Example:

from pathlib import Path


print(Path('.').exists())

Module: statistics

Description: Functions for statistical operations.

Important Methods: mean, median

Example:

import statistics
print(statistics.mean([1, 2, 3, 4]))

Module: subprocess

Description: Spawns new processes, connects to their input/output/error pipes.


Important Methods: run, Popen

Example:

import subprocess
subprocess.run(['echo', 'Hello'])

Module: threading

Description: Higher-level threading interface.

Important Methods: Thread, Lock

Example:

import threading
thread = threading.Thread(target=print, args=("Hello",))
thread.start()

Module: logging

Description: Logging facility for Python.

Important Methods: basicConfig, info, error

Example:

import logging
logging.basicConfig(level=logging.INFO)
logging.info('Info message')

Module: argparse

Description: Command-line option and argument parsing.

Important Methods: ArgumentParser

Example:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--name')
Module: requests

Description: HTTP library for making requests.

Important Methods: get, post

Example:

import requests
response = requests.get('https://example.com')
print(response.status_code)

Module: pandas

Description: Data analysis and manipulation tool.

Important Methods: DataFrame, read_csv

Example:

import pandas as pd
df = pd.DataFrame({'A': [1, 2]})
print(df)

You might also like