Python How To’s
A collection of small, useful, how to’s for Python.
Using Exponents in Python
By now, you probably know how to multiply and divide numbers in Python. Multiplication in Python is fairly simple and easy to do. But what about using exponents? How would you raise a number to the second power, for example? If you’re not sure, you’ll probably find the answer pretty straightforward. To raise a number […]
Read MoreMultiplying and Dividing Numbers in Python
Multiplication is a fundamental operation in the arithmetic and programming world. We can find its use in every program(or in the logic behind every code), no matter how basic it is. Thus a programmer must know how to multiply integers, decimals, complex numbers, and strings in Python to create an efficient and accurate code. In […]
Read MoreUsing Python to Find the Largest Number out of Three
Here’s a useful snippet that will show you how to use Python to find the largest number out of any three given numbers. Basically, the snippet works by using the if…elif…else statements to compare the three numbers against each other and determine which one is the largest. Check out the snippet below to see how […]
Read MoreUsing Python to Check for Number in List
Today’s Python snippet is brought to you by the “in” keyword. In Python, we can use the in keyword for lots of different purposes. In terms of today’s snippet, we’re going to use it to check if a particular number is in a list. To begin, let’s say we have a list called coolNumbers. Take […]
Read MoreHow to Use Python’s len() Method
Python’s len() method can be used to easily find the length of a string. It’s a simple and quick way to measure the length of a string (the number of characters) without having to write a lot of code. The syntax for using the len() method is fairly straightforward, and hard to mess up — […]
Read MoreHow to Generate a Random Number in Python
The aim of a programmer while creating a program is to ensure that the program stands the test for any random input. The program should correctly process the input and accurately calculate the output for any arbitrary data. A programmer must test the program for a wide range of information and amend the code accordingly […]
Read MoreHow to Test for Positive Numbers in Python
The following Python snippet demonstrates how to test if an inputted number is positive, negative, or zero. The code is simple, straightforward, and works with any number or integer. The code uses an if…elif…else statement to determine if a number is greater than 0 (in which case it has to be positive), elif a number […]
Read MoreHow 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 More