Home » Programming » Python

XOR (Exclusive Or) in Python

Python XOR Exclusive Or

This article explains XOR (Exclusive Or) – what it is, why it’s used, and how to implement it in the Python programming language. What is XOR / Exclusive OR XOR – Exclusive Or – is a logical operation commonly used in computer programming. Logically, an XOR condition is true only if the supplied arguments differ. XOR compares two inputs and outputs, true or false, only if they are different. Those inputs are usually true/false boolean values or the result of a logical operation that returns a boolean value. For example, XOR on two values – 1 and 1 is false – they do not differ. XOR on two values … Read more

Home » Programming » Python

Python: View Documentation With the help() Function

Python help() Function

This short article will show you how to use the Python help() function to view the documentation (Docstring) for a Python module, class, or function. Documenting Your Python Code with Docstrings You can document your Python code with a special string called a docstring. We’ve got a whole article on that here. The short version of it is this: put a triple quoted string immediately after declaring a function, class, or module in Python: “”” Just like this “”” …and you can later read from it using the help() … Read more

Home » Programming » Python

What are Python Docstrings and How Are They Used?

Python Docstring

This tutorial will explain what docstrings are in the Python programming language and how they can be used. What is a Docstring in Python? A docstring is a string literal that is used to document your code. A string literal is a sequence of characters 0 or more characters in length, which is to be treated as a single entity – i.e., it’s a string variable of any length. A docstring appears after the definition of a module, class, method, or function and should explain the purpose of the object it … Read more

Home » Programming » Python

C++ vs Python – Which Programming Language to Learn in 2022?

Python vs c++

Here’s a quick primer on the C++ and Python Programming languages to help the beginner or intermediate coders decide which to learn. What is C++? C++ is a compiled general-purpose programming language. It’s an extension of the C programming language – using similar syntax but adding object-oriented programming features like classes, objects, and additional expressions. As C++ is compiled, it is converted to machine language prior to being executed. This means it runs much faster than interpreted languages like Python and means that it has fewer resource overheads, it’s perfect for running on … Read more

Home » Programming » Python

Modulus (Mod), Modulo and Python – Explanation and Code Examples

Python mod Modulus Modulo

This tutorial will explain (hopefully in the simplest terms possible) what modulus and modulo mean and how they can be calculated in the Python programming language. Modulus and Modulo are Different Things! There’s a bit of confusion about this, and it seems that in some places, the terms modulus and modulo are used in place of each other – this is wrong (and confused me too – hence this article)! What is Modulus? In mathematics, the modulus is the absolute value of a number. It’s the non-negative value of a number – or its … Read more

Home » Programming » Python

R vs Python – What Makes them Different? Which is Best?

R vs Python

This article provides a simple comparison of the R and Python programming languages – and what they’re best used for. If you’re looking to learn to program and are interested in data analysis, you’ll probably run into the choice – R or Python? This article breaks down each and why you might choose to use one – or both – of these languages. What is R? R is a programming language designed specifically for statistical computing. It is designed for, and widely used for, processing and analyzing large data sets. What is it Good … Read more

Home » Programming » Python

Calculating Factorials in Python – The Easy Way

Python Factorial

This short article will show you the quickest and easiest way to calculate a factorial in Python using the factorial() function. This article is written for the Python 3 programming language. What is a Factorial, and How is it Calculated? A factorial is a mathematical formula in which a given positive integer is multiplied by all of the positive integers less than itself – the resulting number being the factorial of the original number. It is denoted with ! (exclamation mark) – so the factorial of 4 is written as 4! And is calculated out like so: … Read more

Home » Programming » Python

Checking for Inequality in Python: ‘!=’ vs ‘is not’ [Examples]

Python Not Equal

Should you use the != operator or the ‘is not’ statement when comparing values in Python? Read on to find out! The != Comparison Operator The != operator can be used to compare two variables or statements’ return values. If they are not equal, the statement will return TRUE. Python is forgiving when it comes to comparing variables of different types. So if the type of the variables being compared is different, but the value is the same, it will return TRUE (rather than throwing an error) as they are not equal in both type and value. myNumber … Read more

Home » Programming » Python

How to Use the Python slice() Function, With Examples

Python slice()

The Python slice() function can be used to get a portion of a list, tuple, string, or other sequence. This article will show you how to use it. Python slice() Function Syntax Here’s the syntax for the Python slice() function: slice(START, STOP, STEP) Note that: slice() does not return the specified portion of an object It returns a slice object which is used to retrieve the specified portion from a sequence – it does not contain the sequence itself. This is probably best demonstrated in the below examples START is the starting position (index) of the sequence you … Read more

Home » Programming » Python

What is a Python Dictionary? Explanation and Code Examples

Python dictionary

Here’s everything you need to know about the Dictionary data type in Python, what it can store, and how to use it. Python has several built-in data types for storing data (more than other languages like JavaScript) – from basic types like integers, floating-point numbers, and strings to more complex types like lists, tuples, and dictionaries. What is a Type? A variable’s type defines what kind of value it can store and what can be done with it. What is a Dictionary? A dictionary is a variable type … Read more