Python Variable Scope: Local, Global, Nonlocal and LEGB

Python variable scope: Command Prompt output showing the LEGB rule with local, enclosing, global and built-in names

Scope decides where a Python variable can be seen: a name created inside a function is local, and a name at the top of a file is global. Python looks names up in Local, Enclosing, Global, then Built-in scope, the LEGB rule. These examples ran on Python 3.12.5, and the screenshots come straight from the … Read more >>

How to Use TypeScript Const Arrays?

Const Array in TypeScript

In this tutorial, I will explain how to use the const arrays in TypeScript. I will also show you some examples of using const arrays in TypeScript. What is a Const Array in TypeScript? Let me first explain what a const array is in TypeScript. The const keyword in TypeScript is used to declare variables … Read more >>

How to Use Join() Method to Combine Array of Strings in TypeScript?

Join() Method to Combine Array of Strings in TypeScript

In this tutorial, I will explain how to use TypeScript’s join() method to combine an array of strings into a single string. This method is particularly useful when you need to create a comma-separated list, format strings for display, or generate URLs from an array of parameters. What Is The Join() Method in TypeScript The … Read more >>

How to Use React Pivot Table

React Pivot Table

I’ve found that nothing satisfies a client quite like a powerful data grid. Whether you are building a FinTech dashboard or a retail inventory tracker, users always want to slice and dice their data. For a long time, I struggled to build custom pivot functionality from scratch using basic HTML tables and complex state management. … Read more >>

TypeScript 2D Arrays: Create, Loop and Type Them with Interfaces

TypeScript 2D array guide: Command Prompt output comparing a fill() grid that shares one row with an Array.from grid

A 2D array in TypeScript is an array of arrays, typed number[][] or Array<Array<number>>. Each inner array is a row, and you read a cell with two indexes, row first: sales[1][2]. The outputs below came straight out of the Windows Command Prompt, compiled with tsc –strict on TypeScript 5.2.2 and Node.js v22.22.2. You’ll build empty … Read more >>

NumPy zeros(): Create Arrays of Zeros with np.zeros

NumPy zeros: Command Prompt showing np.zeros creating 2D and 3D arrays and the shape of np.zeros((3, 2))

np.zeros() creates a NumPy array of a given shape filled with zeros. Pass one number for a 1D array or a tuple for more dimensions, and add dtype if you don’t want floats: Below I cover the shape rules, dtypes, zeros_like(), how it compares with np.empty(), and the errors people hit. Everything ran on Python … Read more >>

How to Check if an Element is Not in a List in Python?

Check if an Element is Not in a List in Python

As a Python developer working on various projects, I came across a scenario where I needed to check whether a specific element was present or not in the list. After researching various methods I found a few important ways to achieve this task. In this article, I will explain how to check if an element … Read more >>

How to Convert String to Bytes in Python?

python convert string to bytes

Converting strings to bytes is a common task in Python, especially when dealing with file operations, network communication, or data serialization. As a developer who’s worked with these conversions for years, I will explain various methods to convert string to bytes in Python with examples. If the string holds hex digits like “4a6f”, see convert … Read more >>

Convert String to Variable in Python

Convert String to Variable in Python

In Python, we usually create variables by writing their names directly, like name = “John” or age = 25. But sometimes, you may get variable names from a file, user input, or a form as plain strings like “name” or “age”. In such cases, Python won’t treat these strings as real variables unless you write … Read more >>

Convert String of 1s and 0s to Binary in Python

Convert String of 1s and 0s to Binary in Python

Sometimes in Python, you might come across a string that looks like “101010” just a bunch of 1s and 0s. It looks like binary, but Python treats it as plain text. If you want to use that value as a binary number, for example, to do some math or comparisons, you’ll need to convert it … Read more >>