Python How To’s
A collection of small, useful, how to’s for Python.
How to Test for Prime Numbers in Python
As with any OOP language, you can use Python to conduct calculations and gather information about numbers. One cool thing you can do with Python is test if a number is prime or not. A prime number, as you may remember from math class way back when, is any whole number (it must be greater […]
Read MoreHow to Validate an Email Address Using Python
This snippet shows you how to easily validate any email using Python’s awesome isValidEmail() function. Validating an email means that you’re testing whether or not it’s a properly formatted email. While this code doesn’t actually test if an email is real or fake, it does make sure that the email entered by the user is in […]
Read MoreHow to Display the Date and Time using Python
If you ever have the need to print out and display the date and time in any of your Python projects, it turns out the code for executing those actions is very simple. To get started, you’ll need to import the time module. From there, there are only a few short lines of code standing in the […]
Read MoreCode 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 More