How to Use Python to Convert Fahrenheit to Celsius

There aren’t many easy tricks you can use to easily convert Fahrenheit to Celsius (or vice versa) in your head. Unless you’re great with numbers, the formulas aren’t exactly something you can you figure out using mental math. If you’re not so great with numbers, there’s calculators for that. Or, if you feel so inclined, the formulas […]

Read More

Build Games for Python Using Pygame

Pygame is a set of modules designed to help you write Python games by providing you with extra functionalities and libraries. It’s free, supports Python 3.2 and up, runs on just about every operating system and platforms, and has over a million downloads, so it’s very widely used. Pygame is super speedy because it uses optimized […]

Read More

Using Modulo to Check for Leap Year in Python

We’ve already covered the modulo (%) operator in a previous lesson, but just as a quick refresher, the modulo is an operator that is used to calculate the remainder of one number divided by another. So if you have an equation such as 6 % 3, the answer would be 0, because 3 goes into […]

Read More

Python Code Snippets: Solving the Quadratic Equation

Here’s a fun way to use Python: input any three numbers into a function and you can solve the quadratic equation in milliseconds. Bet you wish you knew about this one back when you were in Algebra I class. The function, written by the people over at Programiz, solves the quadratic equation using basic multiplication […]

Read More

Image Processing with Pillow for Python

If you’ve ever tried to process images on Python and found it to be a total pain, Pillow is here for you. You might know that PIL (Python Imaging Library) has a lot of problems and limitations, and it doesn’t really seem to be in development (it’s hardly ever updated or changed). Here’s where Pillow […]

Read More

Beautiful Soup: A Web Scraper for Python

If you ever need to extract data from a Python site or file quickly and easily, Beautiful Soup, a library designed to help with things like web scraping, is here for you. Beautiful Soup is built on top of popular Python parsers lxml and html5lib, and it’s great for web scraping because it automatically converts […]

Read More

Python Snippets: How to Generate Random String

Python can be a really useful tool to do things like creating random strings. There could be dozens of different reasons why you might want to create a random string of characters and numbers, but one of the more common ones is to use this string as a password. Python Code Snippets offers this really […]

Read More

Quick Tip: How to Print a File Path of a Module

Python provides a really easy and simple way of retrieving file paths of an imported module. This can be really helpful if you’re trying to find a file path quickly and you’re working on a project that has multiple subdirectories, or if you’re using scripts or programs that are primarily accessed through the command line. If […]

Read More

Understanding Python’s Numeric Types

Numeric data types in Python are used to store numeric values. Python has four defined numeric types: plain integers, long integers, floating values, and complex numbers. The int type (plain integers) represents whole numbers that can be either positive or negative. The long type (long integers) are integers of infinite size. They’re written as whole […]

Read More

How to Use the Enumerate() Function

Iterables are undoubtedly some of the most valuable objects in Python. They’re incredibly versatile, helping solve a large assortment of problems. Looping through iterables is an extremely common task, but keeping track of the current element’s index typically demands writing more code.   This is why the enumerate() function was built into Python all the way […]

Read More