XIO

xWire

Posts from every feed QUEST has found across the web — blogs, news, podcasts, channels and more.

AskPython

Python Tutorials for Beginners and Experienced Programmers

Import Math Module in Python

For a circle-area calculation in Python, you can use pi from the math module. Python’s math module provides numeric constants and functions, including math.pi for circle calculations. This article shows how to import pi by name and choose a math function for an operation. TL;DR Import the standard-library module with import math, then call functions […]

Python setattr: Assign Dynamic Attributes

Assigning an object’s attribute by a name held in a string is a task Python’s setattr() handles. The function assigns a value to the attribute named by that string. This article shows how to assign values from a mapping and when to keep keyed data in a dictionary. TL;DR: Python setattr() Python setattr(object, name, value) […]

Python String Template: How to Use It

When the same wording needs different values, Python’s string.Template lets you fill named fields from a mapping or keyword arguments. It replaces dollar-sign placeholders with the values you provide. This article shows how to create a template and choose between strict and safe substitution. TL;DR Use Python’s string.Template when reusable text needs named fields supplied […]

Python Collections: How to Choose the Right Type

When a Python program needs to count repeated values, a collection type can keep a tally for each one. The collections module adds types for tasks such as counting values and grouping items by key. I’ll show how to choose a collection for the task at hand and run a small example of its container […]

What Is Does Not Equal in Python? Examples

When reading Python code, you may see a condition that checks whether two values differ. Python uses != for that comparison. This article explains how to write the comparison and when is not checks whether two references point to different objects. TL;DR: Python Not Equal Operator Write left != right to test whether Python considers […]

Python Metaclass: How Class Creation Works

To understand how Python creates classes, start with metaclasses. A metaclass is the class Python uses to create class objects, and the built-in type is the default metaclass. This article explains how type() inspects or constructs classes and shows how a registry metaclass registers subclasses. TL;DR: Python metaclasses A Python metaclass creates class objects, and […]

String Comparison Python: Equality and Order

To compare text in Python, first choose the question your program needs answered. String comparison evaluates a relationship between text values and returns a Boolean result. This article shows how to test exact equality and check whether a string starts with a prefix. TL;DR: Choose the comparison that matches your question Use == or != […]

5 Ways to Remove a Character from String in Python

A string may need to lose one character while the rest stays in place. Python lets you remove matching text or create a new string without a character at a chosen position. I’ll show how to use replace() to remove every match or only the first one. TL;DR: Pick by value or position Use replace() […]

Python Reverse String: Methods and Examples

When you need the reverse of a Python string, the goal is to produce its characters in reverse order. Python string reversal creates a separate value, and text[::-1] uses a negative step to visit the sequence from right to left. This article shows how to reverse a string with slicing and how to use reversed(text) […]

String Concatenation in Python: A Practical Guide

Putting a name or count into a Python message means assembling text with the values it should show. String concatenation builds a new string from smaller text values using +, str.join(), or formatting. This guide shows how to add separators between strings and choose a method for the values you have. TL;DR Use + for […]

Python Multiple Inheritance: Use MRO and super()

A class may need behavior or attributes from more than one base class. Multiple inheritance lets it list those direct bases, and the method resolution order (MRO) gives Python the sequence it searches for inherited methods. I’ll show how to inspect the MRO and follow a method call through super(). TL;DR Python resolves inherited methods […]

Python Logical Operators: How to Use and, or, not

Python conditions can combine checks when a decision depends on more than one result. Logical operators combine conditions or reverse a condition’s truth value. This article shows how to combine conditions and why an and/or expression may return an operand instead of True or False. TL;DR Python tests logical operands by truth value, but and/or […]

Class Constructor Python: How __init__() Works

A Python class needs a way to give each new object its starting values. The __init__ method receives arguments from a class call and assigns the new instance its starting state. I’ll show how to initialize an object with __init__ and pass initialization through a subclass. TL;DR A Python class call creates an instance, then […]

What Is a Python Static Method? How to Use It

Defining a method in a Python class means choosing what the function receives when it is called. A static method is a function on the class that receives only the arguments you pass, with no automatic self or cls value. This article shows how to define one with @staticmethod and compare calls through the class […]

Python Read Command Line Arguments With argparse

Passing values to a Python script means supplying them when you start it. Python’s argparse module lets you define those inputs and parse them for use in the program. I’ll show how to declare a required filename and set defaults for options callers omit. TL;DR Use argparse for a script that needs named options, type […]

isalpha in Python: String Letter Check

When you check whether a text value contains only letters, you need a clear rule for every character in it. Python’s isalpha() method returns True when a nonempty string consists entirely of Unicode letters. This article shows how to call isalpha() and how empty strings or combining marks affect its result. TL;DR: Check Letters with […]

Python Stack: How to Use Lists and Deques

When you are adding last-in, first-out processing to a Python program, you need a container that keeps the newest item at the top. A list or deque can serve as a stack when you add and remove items at the same end. This article explains how to create a stack with a list and what […]

Python Logging Module: How to Log to Console and File

Runtime messages help show what a Python program is doing as it runs. Python’s built-in logging module records those events by severity and routes them to destinations such as the console or a file. This article shows how to configure console and file output and use named loggers across modules. TL;DR: Python Logging Module Use […]

Python String isalnum() Function

Choosing a test for a Python string starts with deciding which characters it may contain. Python’s str.isalnum() returns True when a nonempty string contains only alphabetic or numeric characters. I’ll show how to test a complete string with str.isalnum() and choose a numeric-specific check when the input must represent a number. TL;DR: Choose the Check […]

Python Breakpoint: How to Use It in pdb

Inspecting a Python program at a chosen point starts with pausing execution there. Python’s breakpoint() function pauses at its call site and opens the configured debugger, which uses pdb by default. This article shows how to use pdb to check a value before continuing the program. TL;DR: Python breakpoint() Python’s breakpoint() pauses execution and opens […]

Critical Values in Python: Find a t Cutoff

To find a t critical value in Python, use the test’s significance level and degrees of freedom. A t critical value is a boundary from the t distribution that you compare with the test statistic. This article shows how to use SciPy to calculate the cutoff and select the appropriate tail probability. TL;DR: Find a […]

Mod in Python: Modulo and math.fmod

When you need the remainder from a division in Python, you can use the % operator or math.fmod(). Modulo gives you the remainder paired with division, and those two options differ in how they handle signs. This article shows how to calculate a remainder and choose the operation that fits your calculation. TL;DR Use % […]

np.linalg.solve() Linear Systems

To solve a set of linear equations, find the values of its unknowns. NumPy’s np.linalg.solve() does that when the coefficient matrix has the same number of rows and columns and its equations are independent. I’ll show how to put the equations into NumPy arrays and check the answer. TL;DR Use np.linalg.solve(A, b) to find x […]

Python Nested Sets: Create a Set of Groups

Grouping unordered collections in Python means choosing a representation that lets one collection hold the groups. A frozenset represents each group as an immutable set, and an outer set can store those groups. I’ll show how to build and query this structure, then explain when a Counter is a better fit for repeated groups. TL;DR […]

Convert String to Int in Python

A Python program may receive digits as text but need a numeric value for whole-number arithmetic. The built-in int() parses integer text into an integer, while str() turns a number into text again. I’ll show how int() converts integer text, then how to convert a number back to text with str(). TL;DR: Use int() and […]

ReLU Function: Python Examples and Use

Understanding what ReLU does to an input helps when you use it in Python. ReLU is an activation function that returns the larger of zero and its input. I’ll show how to define a scalar ReLU function and read its output separately from its derivative, including at zero. TL;DR: ReLU in one line ReLU returns […]

Weather API Python: Analyze Historical Trends

Historical weather records can help answer how conditions varied during a chosen period. A weather API returns data for a requested location and time span, which Python can use to calculate summaries. This article shows how to send a historical data request and interpret its results without treating a past trend as a forecast. TL;DR […]

What Is the Difference Between / and // in Python

When dividing numbers in Python, / and // can give different results. The / operator returns the quotient, while // rounds it down to the greatest whole number no greater than the quotient. A Python example compares their results and types, then the article explains what happens with negative numbers and division by zero. TL;DR […]

OS mkdir: Create Directories in Python

A program may need a directory at a particular filesystem path. Python’s directory-creation calls let you create one directory or create missing parent folders along the path. This article explains the os mkdir operation and shows how os.mkdir() and os.makedirs() create directories. It also covers common errors and permission inputs. TL;DR: Choose the right Python […]