Python Print Hex Without ‘0x’

Problem Formulation If you print a hexadecimal number, Python uses the prefix ‘0x’ to indicate that it’s a number in the hexadecimal system and not in the decimal system like normal integers. However, if you already know that the output numbers are hexadecimal, you don’t necessarily need the ‘0x’ prefix. How to print hex numbers … Read more

How to Display a 1D and 2D Multiplication Table in Python?

Python Multiplication Table For Loop To calculate the multiplication table for a given number, iterate over all values i=0, 1, …, limit in a for loop and use the following statement as a loop body: print(number, ‘x’, i, ‘=’, number * i). This prints all equations, line by line, in the form i x j … Read more

Python Subtraction Operator

Python provides the subtraction operator – to subtract one object from another. The semantics of the subtraction depends on the operands’ data types. For example, subtracting two integers performs the arithmetic difference operation whereas subtracting two sets performs the set difference operation. The specific return value of the minus operator is defined in a data … Read more

Python Program to Add Two Numbers

Add Two Integers The most basic Python program to add two integer numbers stored in variables num_1 and num_2 is the expression num_1 + num_2 using the addition operator. The following code shows how to add two numbers 20 and 22 and print the result 42 to the shell: Add Two Integers with User Input … Read more

How to Divide Two Integers in Python 2 and 3?

In this article, you’ll learn about the division operators // and / in Python 2 and 3. You can check out the version in your Python script as shown here. A short visual overview of the division operator in Python 2 and 3: Assuming two integer values stored in variables a and b, there are … Read more

How To Plot SKLearn Confusion Matrix With Labels?

Summary: The best way to plot a Confusion Matrix with labels, is to use the ConfusionMatrixDisplay object from the sklearn.metrics module. Another simple and elegant way is to use the seaborn.heatmap() function. Note: All the solutions provided below have been verified using Python 3.9.0b5. Problem Formulation Imagine the following lists of Actual and Predicted values … Read more

NumPy Tutorial – Everything You Need to Know to Get Started

This tutorial gives you a simple introduction to Python’s NumPy library. You don’t need any prerequisites to follow the tutorial. My goal was to give a practical and fun NumPy introduction for absolute beginners and with many examples. By reading through this tutorial, you will gain a basic understanding of the most important NumPy functionality. … Read more

What are the Applications of Graphs in Computer Science?

[Reading time: 9 minutes] Graphs are everywhere. They are used in social networks, the world wide web, biological networks, semantic web, product recommendation engines, mapping services, blockchains, and Bitcoin flow analyses. Furthermore, they’re used to define the flow of computation of software programs, to represent communication networks in distributed systems, and to represent data relationships … Read more