Python Basics: Continuing the Library Adventure

Now that you know how to write your first program, it's time for the next step! Python owes its power to a rich collection of modules (libraries) that allow you to perform more advanced tasks. Here are a few basic ones worth knowing:


The os Module - Your Gateway to the Operating System

The os (operating system) module allows your program to communicate with the operating system. With it, you can, for example, create folders, change directories, or list files.

Examples:

Terminal: Colors

System Method (Windows Only)

There is one more method specific to Microsoft systems for changing colors. It does not rely on ANSI codes but on a direct shell command that changes the color of the entire terminal window:

import os
os.system("color 04") # Changes background and text color of the entire window (0-background, 4-text)

The datetime Module - Managing Time and Dates

The datetime module is your go-to tool for working with dates and times. It's essential when you need to get the current time, format dates, or calculate differences between them.

Examples:


The sys Module - Interacting with the Interpreter

The sys module provides access to variables and functions that interact with the Python interpreter. It's useful, for example, for getting command-line arguments passed to a script.

Example:


Other Useful Modules to Start With

Knowing these basic libraries is key to creating more functional programs. It's like learning how to use new tools in your programming toolbox.


👇

▒ Blog Guide: All Programming Posts in One Place. ▹ See