Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 2/2
1.0
Run Code Online (Sandbox Code Playgroud)
这是有意的吗?我强烈记得早期版本的回归int/int=int
?我应该怎么做,是否有新的分区运算符或者我必须总是演员?
如何在Python 2.7中分割两个数字并获得带小数的结果?
我不明白为什么有区别:
在Python 3中:
>>> 20/15
1.3333333333333333
Run Code Online (Sandbox Code Playgroud)
在Python 2中:
>>> 20/15
1
Run Code Online (Sandbox Code Playgroud)
这不是一个模数吗?
def digits(n):
count = 0
if n == 0:
digits = int(n)+1
while (n > 0 ):
count += 1
n = n // 10
return count
print(digits(25)) # Should print 2
print(digits(144)) # Should print 3
print(digits(1000)) # Should print 4
print(digits(0)) # Should print 1
Run Code Online (Sandbox Code Playgroud)
def digits(n):
count = 0
if n == 0:
___
while (___):
count += 1
___
return count
print(digits(25)) # Should print 2
print(digits(144)) #Should print 3
print(digits(1000)) # Should print 4
print(digits(0)) …
Run Code Online (Sandbox Code Playgroud)