Home > Backend Development > Python Tutorial > What does '//' mean in python?

What does '//' mean in python?

烟雨青岚
Release: 2020-07-01 15:52:19
Original
86317 people have browsed it

"//" in python means rounding and dividing, and returns the integer part of the quotient (rounded down). There are other operators in python: " " (addition), "-" (subtraction), "*" (multiplication), "%" (modulo), "/" (division), "**" (power) .

What does '//' mean in python?

python//Indicates integer division and returns the integer part of the quotient (rounded down)

There are other operators in python:

Add - Add two objects a b Output result 30

- Subtract - Get a negative number or subtract one number from another number a - b Output result -10

* Multiply - Multiply two numbers or return a string repeated several times a * b Output result 200

/ Division - Divide x by y b / a Output result 2

% Modulo - Return the remainder of division b % a Output result 0

** Power - Return x raised to the y power a**b is 20 of 10 Power, the output result is 100000000000000000000

// Divide by integer - return the integer part of the quotient (rounded down)

Example:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
a = 21
b = 10
c = 0
 
c = a + b
print "1 - c 的值为:", c
 
c = a - b
print "2 - c 的值为:", c 
 
c = a * b
print "3 - c 的值为:", c 
 
c = a / b
print "4 - c 的值为:", c 
 
c = a % b
print "5 - c 的值为:", c
 
# 修改变量 a 、b 、c
a = 2
b = 3
c = a**b 
print "6 - c 的值为:", c
 
a = 10
b = 5
c = a//b 
print "7 - c 的值为:", c
Copy after login

Result:

1 - c 的值为: 31
2 - c 的值为: 11
3 - c 的值为: 210
4 - c 的值为: 2
5 - c 的值为: 1
6 - c 的值为: 8
7 - c 的值为: 2
Copy after login

Recommended tutorial: "python tutorial"

The above is the detailed content of What does '//' mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template