Category Python Samples

Python How To: List of standard modules included with Python

Python Programming

Here’s a list of the standard Python modules that are included with Python:

  • abc: Abstract Base Classes
  • argparse: Command-line Argument Parsing
  • array: Efficient arrays of numeric values
  • asyncio: Asynchronous I/O, event loop, coroutines and tasks
  • atexit: Exit handlers
  • base64: Base16, Base32, Base64, Base85 Data Encodings
  • bisect: Array bisection algorithm
  • builtins: Built-in objects
  • cProfile: Deterministic profiling of Python programs
  • calendar: General calendar-related functions
  • cgi: Common Gateway Interface support
  • cgitb: Traceback manager for CGI scripts
  • chunk: Tools for iterating over iterables by chunk
  • cmath: Mathematical functions for complex numbers
  • cmd: Support for line-oriented command interpreters
  • codecs: Codec registry and base cl...
Read More

Python How To: Colored text in the terminal

Python Programming

Introduction

In programming, sometimes you need to print colored text to the terminal to make the output more readable or to highlight important information. Python provides several ways to do this.

ANSI Escape Codes

The most common way to print colored text in Python is to use ANSI escape codes. These codes are special sequences of characters that tell the terminal to change the color of the text.

Here’s an example of how to print colored text using ANSI escape codes:

print('\033[1;31;40mHello, World!\033[0m')

This will print “Hello, World!” in red text with a black background.

Let’s break down this code:

  • \033: This is the escape character that tells the terminal to start interpreting the ANSI escape codes.
  • [1;31;40m: This sequence of characters is the ANSI es...
Read More

Variables: Examples and explanations of Python variables.

Python Programming

Introduction

In programming, a variable is a container that holds a value. The value can be a number, text, or any other type of data. Variables are useful because they allow you to store and manipulate data in your programs.

Naming Variables

To create a variable in Python, you first need to give it a name. The name of a variable should be descriptive and meaningful. It should also follow a few rules:

  • The name can only contain letters, numbers, and underscores.
  • The name cannot start with a number.
  • The name should not be a Python keyword, such as if, else, or for.

Here are some examples of valid variable names:

python
age = 42
name = “John”
is_student = True

Assigning Values to Variables

After you have named your variable, you can assign a value to it using t...

Read More