• 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 / Difference Between // and / When Dividing Numbers in Python

Difference Between // and / When Dividing Numbers in Python

February 22, 2022 Leave a Comment

In Python, when doing division, you can use both // and / to divide numbers. // means floor or integer division, and / means floating point division.

print(10/3)
print(10//3)

#Output:
3.333333333333335
3

In Python, we can perform division of numbers in different ways. You can use both // and / to divide numbers

The difference between // and / is that // performs floor division, and / performs floating point division.

Floating point division is regular division, and floor division truncates the resulting quotient.

Below are a few examples of the difference between // and / in Python.

print(10/3)
print(10//3)

print(93/4)
print(93//4)

#Output:
3.333333333333335
3
23.25
23

Performing Floor Division in Python with //

In Python, floor division, or integer division, is the division of two numbers and returning the quotient as a truncated integer value.

Below are a few examples of floor division in Python with a double slash //.

print(10//3)
print(93//4)

#Output:
3
23

Notice here that if you divide a double by an integer with a double slash //, the return value is a double.

print(10.0//3)
print(10//3)

#Output:
3.0
3

Hopefully this article has been useful for you to learn how to understand the difference between // and /, and be able to do division with both single slashes (/) and double slashes (//) in Python.

Other Articles You'll Also Like:

  • 1.  Using Python to Find Second Smallest Value in List
  • 2.  pandas tail – Return Last n Rows from DataFrame
  • 3.  Format Numbers as Currency with Python
  • 4.  How to Remove Vowels from a String in Python
  • 5.  Check if List is Subset of Another List in Python
  • 6.  Python Check if Object Has Attribute
  • 7.  Using Selenium to Get Text from Element in Python
  • 8.  for char in string – How to Loop Over Characters of String in Python
  • 9.  Calculate Sum of Dictionary Values in Python
  • 10.  Check if Number is Between Two Numbers Using 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

x