Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

How to Perform the Python Division Operation?

  • Safa MulaniSafa Mulani
  • April 29, 2020
  • Python Programming Examples
How to Perform the Python Division Operation?

Hey, folks! In this article, we will be focusing on an arithmetic operation – Python Division operation.


Getting started with Python division operation

Python has got various in-built operators and functions to perform arithmetic manipulations.

The '/' operator is used to perform division operation on data values of both the data types i.e. ‘float‘ and ‘int‘.

The beauty of Python ‘/’ operator is that this operator can handle decimal as well as negative values, respectively.

Syntax:

number1 / number2

The operator operates on numeric values and returns a floating point value as a result. The result of the division operation is the Quotient of the operation performed, being represented as a floating point value.

Example 1:

a = input("Enter the value for a:")
b = input("Enter the value of b:")
res = int(a)/int(b)
print(res)

Output:

Enter the value for a:10
Enter the value of b:2
5.0

Example 2:

a = -10
b = 20
res = a/b
print(res)

Output:

-0.5

Python division operation on Tuple

Python floordiv() method along with map() function can be used to perform division operation on various data values stored in a Tuple data structure.

Python floordiv() method is used to perform division operation on all the elements present in the data structure i.e. it performs element wise division operation. Further, Python map() function applies any passed/given function or operation on a set of iterables such as tuples, list, etc.

Syntax:

tuple(map(floordiv, tuple1, tuple2))

The floordiv() method performs integer division i.e. divides the elements and returns only the integer portion of the quotient and skips the decimal portion.

Example:

from operator import floordiv 

 
inp_tup1 = (10,16,9,-4) 
inp_tup2 = (2,-8,4,4) 

tup_div = tuple(map(floordiv, inp_tup1, inp_tup2)) 


print("Resultant tuple after performing division operation : " + str(tup_div)) 

Output:

Resultant tuple after performing division operation : (5, -2, 2, -1)

Python division operation on Dict

Python division operation can be performed on the elements present in the dictionary using Counter() function along with ‘//’ operator.

The Counter() function stores the dictionary key-value data as dict keys and stores the count of the dict elements as the associated values.

The ‘//’ operator performs integer level division on the data elements.

Syntax:

Counter({key : dict1[key] // dict2[key] for key in dict1})

Example:

from collections import Counter

inp_dict1 = {'Python': 100, 'Java': 40, 'C': 36}
inp_dict2 = {'Python': 20, 'Java': -10, 'C': 8}

inp_dict1 = Counter(inp_dict1) 
inp_dict2 = Counter(inp_dict2) 
dict_div = Counter({key : inp_dict1[key] // inp_dict2[key] for key in inp_dict1}) 

print("Resultant dict after performing division operation : " + str(dict(dict_div))) 

In the above example, we have stored the key-value pairs of the input dict in such a way using Counter() function that the input dict now contains the key as the dict elements and the value as the count of elements present in the dict.

Further, we have passed the keys to the ‘//’ operator to perform the division operation.

Output:

Resultant dict after performing division operation : {'Python': 5, 'Java': -4, 'C': 4}

Difference between Python ‘/’ and Python ‘//’ division operators

The basic and probably the only difference between the ‘/’ and ‘//’ division operators is that the '/' operator returns float values as the result of division i.e. it returns the entire quotient( the integer as well as the decimal part).

On the other hand, '//' division operator returns integer value as a result of division i.e. returns only the integer portion of the quotient value.

Example:

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

Output:

3.3333333333333335
3

Conclusion

Thus, in this article, we have understood the ways to perform division operation in Python.


References

  • Python division operation
Safa Mulani
Safa Mulani

An enthusiast in every forthcoming wonders!

Articles: 189
What is Python strftime() function?
Previous Post What is Python strftime() function?
Next Post Using the Tkinter Scale Widget
Using the Tkinter Scale Widget

Related Posts

How to Calculate Distance Between Two Points in Python

How to Calculate Distance Between Two Points in Python

  • November 26, 2026
CIFAR 10 Dataset: Load and Use in Python

CIFAR 10 Dataset: Load and Use in Python

  • November 24, 2026
Maximum A Posteriori Estimation in Python

Maximum A Posteriori Estimation in Python

  • November 24, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.