How To Multiply Int And Float In Python

In this tutorial, we will learn how to multiply integer (int) and floating-point (float) numbers in Python.

Both of these data types are used in various operations while performing calculations, and it is essential to understand the basics of arithmetic operations on them.

Python makes it simple to perform such operations by not requiring explicit typecasting in most cases, unlike some other programming languages.

Step 1: Understanding the data types

Integers: Whole numbers, either negative or positive, are known as integers. In Python, we use the int data type to represent them. For example: 3, -5, 45 are integers.

Floating-Point Numbers: Numbers with a decimal point are called floating-point numbers. In Python, we use the float data type to represent them. For example: 2.5, 0.003, -5.5 are floating-point numbers.

Step 2: Multiplying integers and floats

Python allows us to multiply integers and floating-point numbers directly without the need for explicit type conversion. You can multiply an integer and a float simply by using the * operator.

Here’s a simple example:

The variable result will have the value of the product of integer_num and float_num.

Step 3: Printing the output

To display the result of the multiplication, you can use the print() function. You can either display the result directly or format the output using f-strings, which allows embedding expressions inside string literals, using curly braces {}.

Full Code:


3 multiplied by 2.5 equals 7.5


In this tutorial, we learned how to multiply integers and floating-point numbers in Python. It is relatively simple to perform arithmetic operations on different data types in Python, as the language handles most of the typecasting for us. This allows for more efficient and easy-to-understand code while performing calculations.