python - Python - 从while循环到for循环
问题描述
如何制作一个 for 循环而不是这个 while 循环?
count = 2
data = ["string 1", "some quotation", "ugly phrase"]
while (count != len(data[0])):
# Do some stuff
count += 1
我正在看教程,但我无法弄清楚。
解决方案
for count in range(2, len(data[0])):
# code
推荐阅读
- angular - 为什么这个组件没有应用 css 规则?
- c# - 如果目标足够近,如何使炮塔面向目标旋转并使目标以随机高度和速度围绕炮塔旋转?
- git - 如何正确克隆并切换到现有的 fork 分支
- nlog - NLog 将条目保存到数据库(postgresql),
- yii2 - 有没有办法在 yii2 中动态更改 kartik/select2 上的 maximumSelectionLength?
- java - 确定 Unicode 代码点是否代表来自特定脚本(例如拉丁脚本)的字符?
- variables - Stata以及如何在回归中使用局部变量
- python - 如何复制 matplotlib ax 对象
- python - 读取同一文件夹中的文件 - 改进?
- python - 如何保留具有重复n次值的行并删除不重复的行