• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / How to Multiply Two Numbers in Python

How to Multiply Two Numbers in Python

September 12, 2022 Leave a Comment

To multiply two numbers in Python, you can use the multiplication operator *. You can multiply integers, floats, and decimal variables.

a = 1
b = 2

c = a * b

print(c)

#Output:
2

One of the most fundamental operations in programming is performing different calculations and math.

You can easily multiply two numbers in Python with the * multiplication operator.

You can multiply integers, floats, and decimal variables in Python with *.

The rest of this article will show you examples of how you can use * to multiply two numbers in Python.

How to Multiply Two Integers in Python

The most basic use of * is if you have two integers and you want to multiply them together.

Below shows you a simple example of using / to multiply two integers in Python.

a = 1
b = 2

c = a * b

print(c)

#Output:
3

How to Multiply Two Floats in Python

Another type of number that you can use in Python is a floating point number. Floats allow you to create numbers which have a decimal portion.

Below shows you a simple example of using * to multiply two floats in Python.

a = 1.0
b = 2.0

c = a * b

print(c)

#Output:
2.0

How to Multiply a Float and an Integer in Python

You can multiply a float and an integer together with *. The result will be a float.

Below shows you how to multiply a float and an integer together in Python.

a = 1
b = 2.0

c = a * b

print(c)

#Output:
2.0

How to Multiply Two Decimals in Python

Another type of number that you can use in Python is a decimal. The decimal module provides support for fast correctly rounded decimal floating point arithmetic.

Below shows you a simple example of using * to multiply two decimals in Python.

from decimal import *

a = Decimal('1.01')
b = Decimal('2.02')

c = a * b

print(c)

#Output:
2.0402

Hopefully this article has been useful for you to learn how to multiply two numbers in Python.

Other Articles You'll Also Like:

  • 1.  Convert String to Boolean Value in Python
  • 2.  Python cos – Find Cosine of Number in Radians Using math.cos()
  • 3.  Python acosh – Find Hyperbolic Arccosine of Number Using math.acosh()
  • 4.  Solve Python Object Does Not Support Indexing Error
  • 5.  Python Increment Counter with += Increment Operator
  • 6.  Are Dictionaries Mutable in Python? Yes, Dictionaries are Mutable
  • 7.  Using pandas resample() to Resample Time Series Data
  • 8.  Changing Python Turtle Speed with speed() Function
  • 9.  Check if String Does Not Contain Substring in Python
  • 10.  How to Ask a Question in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy