Python Guides
Free Python Tutorials with Code Examples
- Website
- pythonguides.com · all feeds from this site
- Feed URL
https://pythonguides.com/feed/
Read it in your FeedListing reader
Or add to: Feedly Inoreader Raw feed
Latest posts
-
pip install from pyproject.toml (With Examples)
For a pip install from pyproject.toml, open a terminal in the folder that holds the file and run pip install .. The dot means “this project”: pip reads pyproject.toml, builds the package and installs it along with its dependencies: I tested every command on a tiny invoice…
-
How to Rename a Key in a Dictionary in Python
Python dictionaries can’t rename a key directly, so you rename a key in a dictionary by adding the value under the new name and deleting the old one. pop() does both in a single line: Every result here came from Python 3.12.5, with a small customer record from Austin as the…
-
Hangman Game Code in Python (Full Program)
Hangman game code in Python comes down to four pieces: pick a secret word with random.choice(), show it as underscores, keep guessed letters in a set, and count misses until the drawing is complete. The masking line does most of the work: I played the full game below in a real…
-
How to Delete All Files in a Directory in Python
To delete all files in a directory with Python, loop over the folder and remove each file with Path.unlink() (or os.remove()), skipping subfolders. Use shutil.rmtree() only when you want the folder gone too: These deletions are permanent, so every example here works on a…
-
Game Engines That Use Python (2026 Comparison)
The main game engines that use Python are Pygame (and its community fork pygame-ce), Arcade, Panda3D, Ursina, Ren’Py and Pyxel. Godot’s GDScript looks like Python but isn’t, and Unreal uses Python only for editor scripting: To show what Python game code looks like, I built a…
-
Python Extension for VS Code: Install and Set Up
The Python extension for VS Code is Microsoft’s free Python extension (ID ms-python.python). Install it from the Extensions view, select your interpreter, and VS Code gains IntelliSense, running, debugging, testing and environment management for Python: I checked everything on…
-
Higher Order Functions in Python (With Examples)
Higher order functions in Python are functions that take another function as an argument, return a function, or both. You already use them: sorted(items, key=...), map() and filter() all accept a function: The output below is from Python 3.12.5, using small order and pricing…
-
Fuzzy String Matching in Python (difflib and RapidFuzz)
Fuzzy string matching in Python scores how similar two strings are, so “Philadelpia” can still match “Philadelphia”. The standard library’s difflib does it with no installs, and the RapidFuzz package does it much faster with smarter scorers: All scores below come from real runs…
-
How to Update Python in the Terminal (Windows, Mac, Linux)
Here’s how to update Python in the terminal: on Windows, run py install --update with the Python install manager (or winget upgrade Python.Python.3.14); on a Mac, run brew upgrade python@3.14; on Linux, install the newer version alongside the system one. Then check it: The…
-
Python Quadratic Equation Solver (With Examples)
For a Python quadratic equation ax² + bx + c = 0, compute the discriminant b² - 4ac and plug it into the quadratic formula. Use cmath.sqrt so negative discriminants give complex roots instead of an error: All roots below were computed on Python 3.12.5 with NumPy 2.5.3, including…
-
Fix: TypeError ‘list’ object is not callable in Python
TypeError: 'list' object is not callable in Python means you put parentheses after something that’s a list, so Python tried to call it like a function. Usually you named a variable list, or used () where indexing needs []: Every traceback below is real output from Python 3.12.5,…
-
What Does isalpha() Do in Python? (With Examples)
What does isalpha do in Python? str.isalpha() returns True when every character in a string is a letter and the string isn’t empty. A single space, digit or punctuation mark makes it False: I tested each example on Python 3.12.5, including accented and non-English letters.…
-
Multiple Linear Regression in Python (scikit-learn and statsmodels)
Multiple linear regression in Python predicts one number from several inputs. With scikit-learn it takes three lines: pick your feature columns, call LinearRegression().fit(X, y), and read the coefficients: To make the results checkable, I simulated 400 home sales where I know…
-
What Is yield in Python? Generators Explained
So what is yield in Python? It’s a keyword that turns a function into a generator: instead of returning one result and ending, the function hands back a value, pauses, and picks up where it left off the next time you ask for a value: The prints inside each generator below show…
-
How to Import math in Python (and Use It)
Here’s how to import math in Python: write import math at the top of your file, then call functions with the math. prefix, like math.sqrt(16). The math module ships with Python, so there’s nothing to install: I ran every snippet with Python 3.12.5 and copied the output exactly,…
-
Run Length Encoding in Python (Encode and Decode)
Run length encoding in Python replaces each run of repeated characters with a count and the character, so "AAABBB" becomes "3A3B". The shortest version uses itertools.groupby: Every encoder and decoder below was run on Python 3.12.5 with a round-trip check, so you can trust that…
-
Factory Design Pattern in Python (With Examples)
The factory design pattern in Python means letting a function (or class method) decide which class to create, so your code asks for an object by name, not by class. In Python, a dictionary of classes is often all you need: Each pattern below ran on Python 3.12.5, using shipping,…
-
Python Replace with Regular Expression (re.sub Guide)
For a Python replace with a regular expression, use re.sub(pattern, replacement, text). It finds every match of the pattern and returns a new string with each one replaced: All output below is from Python 3.12.5, using made-up orders, phone numbers and prices. I’ll cover the…
-
Running Shell Commands in Python (subprocess Guide)
For running shell commands in Python, use subprocess.run(). Pass the command as a list, add capture_output=True, text=True to get its output as a string, and check returncode to see whether it worked: These examples ran on Windows in Command Prompt with Python 3.12.5; the same…
-
Python for Loop in One Line (One-Liner Examples)
A Python for loop on one line can be written two ways: put a short body after the colon, like for x in items: print(x), or, when you’re building a new list, use a comprehension such as [x * 2 for x in items]: I ran each one-liner on Python 3.12.5, and the screenshots come ...…