10 2 python


Asked by wiki @ & viewed by 12 persons


Difference between “//” and “/” in Python 2 [duplicate]

Python 2 has two division operators: / and //. The following output:

========================================= RESTART: Shell =========================================
>>> for x in range(10):
        for y in range(1, 10):
                print x,'//',y,'=',x//y
                print x,'/',y,'=',x/y
                print


0 // 1 = 0
0 / 1 = 0

0 // 2 = 0
0 / 2 = 0

0 // 3 = 0
0 / 3 = 0

0 // 4 = 0
0 / 4 = 0

0 // 5 = 0
0 / 5 = 0

0 // 6 = 0
0 / 6 = 0

0 // 7 = 0
0 / 7 = 0

0 // 8 = 0
0 / 8 = 0

0 // 9 = 0
0 / 9 = 0

1 // 1 = 1
1 / 1 = 1

1 // 2 = 0
1 / 2 = 0

1 // 3 = 0
1 / 3 = 0

1 // 4 = 0
1 / 4 = 0

1 // 5 = 0
1 / 5 = 0

1 // 6 = 0
1 / 6 = 0

1 // 7 = 0
1 / 7 = 0

1 // 8 = 0
1 / 8 = 0

1 // 9 = 0
1 / 9 = 0

2 // 1 = 2
2 / 1 = 2

2 // 2 = 1
2 / 2 = 1

2 // 3 = 0
2 / 3 = 0

2 // 4 = 0
2 / 4 = 0

2 // 5 = 0
2 / 5 = 0

2 // 6 = 0
2 / 6 = 0

2 // 7 = 0
2 / 7 = 0

2 // 8 = 0
2 / 8 = 0

2 // 9 = 0
2 / 9 = 0

3 // 1 = 3
3 / 1 = 3

3 // 2 = 1
3 / 2 = 1

3 // 3 = 1
3 / 3 = 1

3 // 4 = 0
3 / 4 = 0

3 // 5 = 0
3 / 5 = 0

3 // 6 = 0
3 / 6 = 0

3 // 7 = 0
3 / 7 = 0

3 // 8 = 0
3 / 8 = 0

3 // 9 = 0
3 / 9 = 0

4 // 1 = 4
4 / 1 = 4

4 // 2 = 2
4 / 2 = 2

4 // 3 = 1
4 / 3 = 1

4 // 4 = 1
4 / 4 = 1

4 // 5 = 0
4 / 5 = 0

4 // 6 = 0
4 / 6 = 0

4 // 7 = 0
4 / 7 = 0

4 // 8 = 0
4 / 8 = 0

4 // 9 = 0
4 / 9 = 0

5 // 1 = 5
5 / 1 = 5

5 // 2 = 2
5 / 2 = 2

5 // 3 = 1
5 / 3 = 1

5 // 4 = 1
5 / 4 = 1

5 // 5 = 1
5 / 5 = 1

5 // 6 = 0
5 / 6 = 0

5 // 7 = 0
5 / 7 = 0

5 // 8 = 0
5 / 8 = 0

5 // 9 = 0
5 / 9 = 0

6 // 1 = 6
6 / 1 = 6

6 // 2 = 3
6 / 2 = 3

6 // 3 = 2
6 / 3 = 2

6 // 4 = 1
6 / 4 = 1

6 // 5 = 1
6 / 5 = 1

6 // 6 = 1
6 / 6 = 1

6 // 7 = 0
6 / 7 = 0

6 // 8 = 0
6 / 8 = 0

6 // 9 = 0
6 / 9 = 0

7 // 1 = 7
7 / 1 = 7

7 // 2 = 3
7 / 2 = 3

7 // 3 = 2
7 / 3 = 2

7 // 4 = 1
7 / 4 = 1

7 // 5 = 1
7 / 5 = 1

7 // 6 = 1
7 / 6 = 1

7 // 7 = 1
7 / 7 = 1

7 // 8 = 0
7 / 8 = 0

7 // 9 = 0
7 / 9 = 0

8 // 1 = 8
8 / 1 = 8

8 // 2 = 4
8 / 2 = 4

8 // 3 = 2
8 / 3 = 2

8 // 4 = 2
8 / 4 = 2

8 // 5 = 1
8 / 5 = 1

8 // 6 = 1
8 / 6 = 1

8 // 7 = 1
8 / 7 = 1

8 // 8 = 1
8 / 8 = 1

8 // 9 = 0
8 / 9 = 0

9 // 1 = 9
9 / 1 = 9

9 // 2 = 4
9 / 2 = 4

9 // 3 = 3
9 / 3 = 3

9 // 4 = 2
9 / 4 = 2

9 // 5 = 1
9 / 5 = 1

9 // 6 = 1
9 / 6 = 1

9 // 7 = 1
9 / 7 = 1

9 // 8 = 1
9 / 8 = 1

9 // 9 = 1
9 / 9 = 1

>>> 

proves (almost?) all the time a/b equals a//b. Is there any time that it isn't? If not, why did Python 2 include two operators that do the same thing?

Do you know the better answer?

Similar questions

10 2 in python

Asked by wiki @ & viewed by 5 persons

What is the difference between '/' and '//' when used for division? Is there a benefit to using one over …

Range 0 10 2 python

Asked by wiki @ & viewed by 23 persons

How to use a decimal range() step value? Is there a way to step between 0 and 1 by 0.1? …

In python 3 what is the output of 1 2

Asked by wiki @ & viewed by 6 persons

Difference between “//” and “/” in Python 2 [duplicate] This question already has answers here: What is the difference between …

Python create a list of numbers from 1 to 10

Asked by wiki @ & viewed by 11 persons

Python - Create list with numbers between 2 values? How would I create a list with values between two values …

Python error takes 1 positional argument but 2 were given

Asked by wiki @ & viewed by 9 persons

TypeError: method() takes 1 positional argument but 2 were given If I have a class... class MyClass: def method(arg): print(arg) …

Python program to print multiplication table from 1 to 10

Asked by wiki @ & viewed by 47 persons

A function that prints out tables from 1 to 10 using iteration def tablesOneToTen(): # a function that will print …

Python winerror 2 the system cannot find the file specified

Asked by wiki @ & viewed by 7 persons

FileNotFoundError: [WinError 2] The system cannot find the file specified: import os def rename(directory): for name in os.listdir(directory): print(name) os.rename(name,"0"+name) …

Filenotfounderror errno 2 no such file or directory in python

Asked by wiki @ & viewed by 5 persons

Python error: FileNotFoundError: [Errno 2] No such file or directory I am trying to open the file from folder and …

Assertionerror python 2 detected odoo requires python 3.5 to run

Asked by wiki @ & viewed by 6 persons

Can I assert the python version before the interpreter parses the code? I want to inform the user which python …

X 10 python

Asked by wiki @ & viewed by 11 persons

Exercise on Summing Digits | What's with n // = 10 [duplicate] This question already has answers here: Closed 8 …

Solaris 10 python

Asked by wiki @ & viewed by 6 persons

How to Install pip on Solaris 10? I am new to python learning.I need to install pip on python2.6. From …

Tensorflow python framework errors_impl internalerror could not allocate ndarray

Asked by wiki @ & viewed by 11 persons

CNN model on Rapberry Pi I am working on a project that involves glaucoma detection on the Raspberry pi 3B. …

Temp 10 in python

Asked by wiki @ & viewed by 5 persons

Printing a series of armstrong number using python is showing error I am beginner in python and i want to …

Which function is used to close a file in python

Asked by wiki @ & viewed by 36 persons

How to close a file in the main function in python? I am writing a function that helps in opening …

Python program to convert decimal to binary using while loop

Asked by wiki @ & viewed by 25 persons

how to convert decimal to binary by using repeated division in python how to convert decimal to binary by using …

Most viewed questions


Python strftime milliseconds

Asked by wiki @ & viewed by 200 persons

Format a datetime into a string with milliseconds I want to have a datetime string from the date with milliseconds. …

What does the percent sign mean in python

Asked by wiki @ & viewed by 136 persons

What does the percentage sign mean in Python In the tutorial there is an example for finding prime numbers: >>> …

Self keyword in python

Asked by wiki @ & viewed by 134 persons

What is the purpose of the word 'self'? What is the purpose of the self word in Python? I understand …

Check object type python

Asked by wiki @ & viewed by 132 persons

Determine the type of an object? Is there a simple way to determine if a variable is a list, dictionary, …

Alphabetical sort python

Asked by wiki @ & viewed by 131 persons

Python data structure sort list alphabetically I am a bit confused regarding data structure in python; (),[], and {}. I …

Correlation matrix python

Asked by wiki @ & viewed by 131 persons

Plot correlation matrix using pandas I have a data set with huge number of features, so analysing the correlation matrix …

Python random

Asked by wiki @ & viewed by 127 persons

Generate random integers between 0 and 9 How can I generate random integers between 0 and 9 (inclusive) in Python? …

Python create dataframe from list

Asked by wiki @ & viewed by 124 persons

Python: create a pandas data frame from a list I am using the following code to create a data frame …

How to add a column to dataframe python

Asked by wiki @ & viewed by 123 persons

Adding new column to existing DataFrame in Python pandas I have the following indexed DataFrame with named columns and rows …

Python one line for loop

Asked by wiki @ & viewed by 123 persons

Python one-line “for” expression I'm not sure if I need a lambda, or something else. But still, I need the …

Why we use self in python

Asked by wiki @ & viewed by 116 persons

What is the purpose of the word 'self'? What is the purpose of the self word in Python? I understand …

Shape 0 python

Asked by wiki @ & viewed by 115 persons

x.shape[0] vs x[0].shape in NumPy Let say, I have an array with x.shape = (10,1024) when I try to print …

Python print working directory

Asked by wiki @ & viewed by 112 persons

Find current directory and file's directory [duplicate] This question already has answers here: How do you properly determine the current …

Image shape python

Asked by wiki @ & viewed by 110 persons

Python OpenCV2 (cv2) wrapper to get image size? How to get the size of an image in cv2 wrapper in …

Interface grafica python

Asked by wiki @ & viewed by 108 persons

Como criar interface gráfica em Python? [duplicada] Essa pergunta já tem uma resposta aqui: É possível criar interfaces gráficas para …