Python How To’s
A collection of small, useful, how to’s for Python.
Code Snippets: Using Python to Solve the Quadratic Equation
Python is a versatile and powerful coding language that can be used to execute all sorts of functionalities and processes. One of the best ways to get a feel for how Python works is to use it to create algorithms and solve equations. In this example, we’ll show you how to use Python to solve […]
Read MoreHow to Use Python’s If Statement
In Python, an If statement contains code that is executed based on whether or not certain conditions are true. For example, if you want to print something, but you want the execution of that printed text to be contingent upon other conditions, you’re going to need to use an If statement. The basic syntax for […]
Read MoreQuick Tip: Using Python’s In Operator
In Python, the word “in” can be used as a membership test operator. It’s a great way to check if a certain value exists in a Python object. See the example below to understand how it’s used in context: >>>a = “Learning Python is super fun!” >>>”super” in a True The above example demonstrates how the […]
Read MoreHow to Merge Lists in Python
If you ever have multiple lists in Python that you want to combine in one list, don’t panic. Python actually makes it really easy to perform a function like this. You can combine and concatenate lists just by using the plus (+) symbol — seriously, it doesn’t get much easier than that. If you want […]
Read MoreUsing Python’s Random Module to Generate Integers
In Python, the random module allows you to generate random integers. It’s often used when you need to a number to be picked at random or to pick a random element from a list. Using it is actually really straightforward. Let’s say you want to print a random integer within a given range, like 1-100. Here’s how […]
Read MorePython Basics: Strings and Printing
Strings are a really commonly used type in Python, and can be formed simply by placing quotes around characters. Anything that resides inside of quotations is a string (single quotes or double quotes are both acceptable). To create a string, you simply need to assign these characters inside quotes as values to a variable, like this: […]
Read MorePython 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 MorePython’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 MoreResetting 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 MoreSwapping 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