Types of Errors in Python (With Real Examples)

Types of errors in Python: Command Prompt output of common built-in exceptions and their messages

There are three main types of errors in Python: syntax errors, which stop the code from running at all; runtime errors (exceptions), which crash it partway through; and logical errors, which run fine but give the wrong answer. All the error messages below are copied from Python 3.12.5 running in a Windows Command Prompt, so … Read more >>

How to Remove Trailing Zeros from a Decimal in Python

Remove trailing zeros from a decimal in Python: Command Prompt output of Decimal normalize() with the :f format

A value like 2.500 reads better as 2.5. To remove trailing zeros from a decimal in Python, call normalize() on a Decimal and format the result with :f, so whole numbers don’t turn into scientific notation: Pantry weights in pounds serve as the sample data here, and each script was run in Command Prompt with … Read more >>

Python vs C#: Which Language Should You Learn in 2026?

Python vs C#: the same sales report program built and run with dotnet run in Command Prompt

Python vs C# comes down to this: Python is shorter to write and rules AI and scripting, while C# is a compiled, statically typed .NET language that runs faster and powers enterprise apps and Unity games. Here’s one line of the same report in each: To keep this honest, I wrote one small sales report … Read more >>

Difference Between List, Tuple, Set and Dictionary in Python

Difference between list, tuple, set and dictionary in Python: Command Prompt output of all four types

Four brackets, four behaviors. The list vs tuple vs set vs dictionary in Python choice comes down to three questions: can it change, does it keep order, and does it allow duplicates? A list is changeable and ordered, and a tuple is fixed. A set keeps unique items only, while a dictionary maps keys to … Read more >>

is None vs == None in Python: What’s the Difference?

is None vs == None in Python: Command Prompt output comparing both checks on None and on 0

Use is None. The difference between is None vs == None in Python is that is checks whether a name points to the one and only None object, while == asks the object’s __eq__ method, which a class can rewrite to say anything: I ran these snippets on Python 3.12.5, NumPy 2.5.3 and pandas 3.0.6; … Read more >>

How to Count Words in a File (and a String) in Python

Count words in a file in Python: Command Prompt output showing line, word and character counts for a reviews file

Python doesn’t need a library for this. To count words in a file in Python, read the file into a string, call split() with no arguments, and take len() of the list. Every run of spaces, tabs and newlines counts as one break: Below I’ll use a small file of US customer reviews, plus a … Read more >>

How to Get the Decimal Part of a Number in TypeScript

TypeScript decimal part of a number: Command Prompt output comparing % 1, trunc and floor for negative numbers

You can get the decimal part of a number in TypeScript with the remainder operator: x % 1 returns everything after the decimal point as a number. For 24.75 that’s 0.75, and an integer gives 0: My test machine runs TypeScript 7.0.2 and Node.js v22.22.2; I built each file with strict checks on and copied … Read more >>

How to Find a Key by Value in a TypeScript Dictionary

Find key by value in a TypeScript dictionary: Command Prompt output of Object.keys with find

To find a key by value in a TypeScript dictionary, get the keys with Object.keys(), type them as keyof, and call find() to return the first key whose value matches. If nothing matches, you get undefined: Nothing below is pseudo-code: each lookup went through tsc –strict and then Node, using TypeScript 7.0.2 and Node.js v22.22.2, … Read more >>

ReferenceError: fetch is not defined in TypeScript (Fixed)

ReferenceError fetch is not defined in TypeScript: Command Prompt output from Node.js with and without global fetch

ReferenceError: fetch is not defined in TypeScript means your compiled JavaScript is running somewhere that has no global fetch, usually Node.js older than 18 or a Jest jsdom test. Upgrade Node, or load node-fetch first: Every example below ran on TypeScript 7.0.2 and Node.js v22.22.2 with strict mode, and I copied the output straight from … Read more >>

Web Scraping with Python: A Step-by-Step Tutorial

Scraping web data with Python: a Requests and Beautiful Soup crawler saving books to CSV

Scraping web data with Python comes down to two steps: download the page with requests, then pull out the parts you need with Beautiful Soup. Here’s the whole idea in four lines: Together we’ll build a small scraper for books.toscrape.com, a fake bookstore made for practice, on Python 3.12.5, requests 2.34.2 and beautifulsoup4 4.15.0. The … Read more >>