100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4,6 TrustPilot
logo-home
Otro

Libraries and Modules in Python: A Comprehensive Guide with Examples

Puntuación
-
Vendido
-
Páginas
6
Subido en
24-01-2025
Escrito en
2024/2025

This document introduces libraries and modules in Python, explaining how to use built-in and external libraries. Learn about Python’s standard library, importing modules, and popular libraries like NumPy, pandas, and Matplotlib with practical examples. Perfect for first-year Computer Science students.

Mostrar más Leer menos
Institución
Grado

Vista previa del contenido

Libraries and Modules in Python
Libraries and modules are essential to Python, enabling developers to reuse code,
reduce redundancy, and leverage powerful prebuilt functionalities. Python comes
with a rich standard library, and you can also install third-party libraries to extend
its capabilities.



1. What are Modules and Libraries?
 A module is a file containing Python code (functions, classes, variables) that
can be imported and reused.
 A library is a collection of modules packaged together for specific tasks.

Example:

A single .py file is a module, whereas libraries like NumPy or Pandas contain
multiple modules.



2. Importing Modules
Python provides the import statement to use modules in your program.

Importing a Module:

import math
print(math.sqrt(16)) # Output: 4.0

Importing Specific Functions or Variables:

from math import sqrt, pi
print(sqrt(25)) # Output: 5.0
print(pi) # Output: 3.141592653589793

Using Aliases:

, import math as m
print(m.pow(2, 3)) # Output: 8.0

Importing All Functions (Not Recommended):

from math import *
print(sin(pi / 2)) # Output: 1.0


3. Built-in Libraries
Python's standard library includes modules for common tasks. Here are some
popular ones:

1. os: Operating System Operations

import os
print(os.getcwd()) # Get the current working directory
os.mkdir("test_folder") # Create a new folder
os.rmdir("test_folder") # Remove the folder

2. sys: System-Specific Parameters and Functions

import sys
print(sys.version) # Python version
print(sys.argv) # Command-line arguments

3. datetime: Date and Time Operations

from datetime import datetime
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S")) # Output: e.g., 2024-12-24
10:30:45




4. random: Generating Random Numbers

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
24 de enero de 2025
Número de páginas
6
Escrito en
2024/2025
Tipo
Otro
Personaje
Desconocido

Temas

$7.39
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
rileyclover179

Conoce al vendedor

Seller avatar
rileyclover179 US
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
0
Miembro desde
1 año
Número de seguidores
0
Documentos
252
Última venta
-

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes