简体   繁体   English

从本书介绍到使用Python进行计算和编程,如何理解关于范围的这句话

[英]How to understand this sentence about range, from the book Introduction to Computation and Programming Using Python

I am self learning Python via the book Introduction to Computation and Programming Using Python and I'm stuck on this sentence in the book about range: 我通过《 使用Python进行计算和编程简介 》一书自学Python,在本书中有关范围的这一句我一字不漏:

If step is positive, the last element is the largest integer start + i*step less than stop. 如果step为正,则最后一个元素为最大整数start + i * step小于stop。

I think I understand how range works: range(A, B, z) will start at A and try to "reach" B with a step size of z, and it B-1 will be the largest result if the step is 1. But I don't understand the sentence above by Prof. Guttag. 我想我了解range的工作原理:range(A,B,z)将从A开始,并尝试以z的步长“到达” B,如果步长为1,则B-1将是最大的结果。但是我不理解古塔格教授的上述句子。

The last element will no doubt be the largest integer will be the largest if the step is positive. 如果步长为正,则最后一个元素无疑将是最大整数。 But wouldn't the different between the last element and stop be (Stop - (Start + i*step))? 但是最后一个元素和停止之间的区别是(Stop-(Start + i * step))吗?

Why did he say that it will be start + i*step less than stop. 他为什么说它将开始+步数小于停止。 ?

You are understanding it correctly. 您正确理解了它。 He doesn't mean that this is the quantity by which it is smaller than stop . 他并不意味着这是比stop小的数量。 He means that 他的意思是

  • it is the largest integer 它是最大的整数
  • that has the form start + i*step 形式为start + i*step
  • and is less than (smaller than) stop 并且 小于 (小于) stop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM