Python While Loop

The while loop in Python is basically just a way to construct code that will keep repeating while a certain expression is true. To create a while loop, you’ll need a target statement and a condition, and the target statement is the code that will keep executing for as long as the condition remains true. The syntax […]

Read More

Using Sparts to Write Python Code

Sparts is a Python library developed by Facebook to eliminate skeleton code. The main purpose of the library is to make it easy to implement services without having to write excess code, so you can create prototypes really quickly. To learn the basics of Sparts, be sure to read the documentation. The way that Sparts […]

Read More

Python’s Count Method

In Python, the count method returns the count of how many times an object occurs in a list. The syntax for the count method is really straightforward: list.count(obj) The above example represents the basic syntax for this method. When you’re using it in context, you’ll need to replace the ‘list’ keyword with the actual name […]

Read More

Python Tools: Pyflame

Pyflame is new a tool brought to us by Uber’s engineering team (you can read about the conception of the idea here) that many Python coders will find very useful. The tool is used to generate flame graphs for Python processes.   Pyflame works by using the ptrace(2) system call to analyze the currently-executing stack trace […]

Read More

Using YAPF (Yet Another Python Formatter)

Yet Another Python Formatter (YAPF) is a valuable tool for writing Python. YAPF is an open-source Python Formatter that makes writing clean Python code a lot easier, so you can spend more time writing code and less time worrying about how it looks. One of the great advantages of using this formatter (besides the pretty […]

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

Quick Tip: Reversing Strings in Python

There is no built in function in Python for reversing a string, but that doesn’t mean it can’t be done. To reverse a string in Python, a little bit of extended slice syntax needs to be used, so you’re going to have to add something to your code that looks like this: [::-1]. Here’s what […]

Read More

Resetting the Recursion Limit

What Is The Recursion Limit? A recursive function is one that calls itself, looping through data to generate a result. However, in Python, there is a limit to the number of times a function can call itself. The limit is set to the maximum depth of Python’s interpreter stack.  Python’s default recursion limit is 1000, […]

Read More

Swapping Values in Python

Swapping the values of two variables in Python is actually a really simple task. Python makes it fairly easy to swap two values without a lot of bulky code or weird hacks. Check out how easy it is to swap two numbers with each other using the built in methods below: x, y = 33, […]

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