Geschrieben von Student*innen, die bestanden haben Sofort verfügbar nach Zahlung Online lesen oder als PDF Falsches Dokument? Kostenlos tauschen 4,6 TrustPilot
logo-home
Andere

Libraries and Modules in Python: A Comprehensive Guide with Examples

Bewertung
-
Verkauft
-
seiten
6
Hochgeladen auf
24-01-2025
geschrieben in
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.

Mehr anzeigen Weniger lesen
Hochschule
Kurs

Inhaltsvorschau

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

Schule, Studium & Fach

Hochschule
Kurs

Dokument Information

Hochgeladen auf
24. januar 2025
Anzahl der Seiten
6
geschrieben in
2024/2025
Typ
ANDERE
Person
Unbekannt

Themen

6,62 €
Vollständigen Zugriff auf das Dokument erhalten:

Falsches Dokument? Kostenlos tauschen Innerhalb von 14 Tagen nach dem Kauf und vor dem Herunterladen kannst du ein anderes Dokument wählen. Du kannst den Betrag einfach neu ausgeben.
Geschrieben von Student*innen, die bestanden haben
Sofort verfügbar nach Zahlung
Online lesen oder als PDF

Lerne den Verkäufer kennen
Seller avatar
rileyclover179

Lerne den Verkäufer kennen

Seller avatar
rileyclover179 US
Folgen Sie müssen sich einloggen, um Studenten oder Kursen zu folgen.
Verkauft
-
Mitglied seit
1 Jahren
Anzahl der Follower
0
Dokumente
252
Zuletzt verkauft
-

0,0

0 rezensionen

5
0
4
0
3
0
2
0
1
0

Kürzlich von dir angesehen.

Warum sich Studierende für Stuvia entscheiden

on Mitstudent*innen erstellt, durch Bewertungen verifiziert

Geschrieben von Student*innen, die bestanden haben und bewertet von anderen, die diese Studiendokumente verwendet haben.

Nicht zufrieden? Wähle ein anderes Dokument

Kein Problem! Du kannst direkt ein anderes Dokument wählen, das besser zu dem passt, was du suchst.

Bezahle wie du möchtest, fange sofort an zu lernen

Kein Abonnement, keine Verpflichtungen. Bezahle wie gewohnt per Kreditkarte oder Sofort und lade dein PDF-Dokument sofort herunter.

Student with book image

“Gekauft, heruntergeladen und bestanden. So einfach kann es sein.”

Alisha Student

Häufig gestellte Fragen