循环语句
来源:互联网 发布:nginx 配置多目录访问 编辑:程序博客网 时间:2024/05/18 21:07
说到循环,印象最深刻的就是,dos界面不断输出刷新的死循环场景,那可真是学C语言的时候噩梦。但对于现在的我们来说,写循环就像写每行代码后面的分号一样,如行云流水一般。python同样是如此,不信类比一下。
for(int i = 0; i < 5; i++){ cout << "Hello world!" << endl; cout << "Hello"}
for i in range(0, 5): print("Hello world!") print("Hello")
怎么样?是不是很像?! 是不是很好记?
print("是!!!")
对了,python是没有大括号来区分代码块的,区分方式只有缩进,拿for循环来说吧,要放在同一个循环中的语句,需要保持相同的缩进位数,就像样例中的一样。还有一种while循环==
直接上代码吧==
假如我需要输出五个Hello world!并且后面附上次数。
i = 0while i < 5: i = i + 1; print("Hello world! %s" % i)
输出
Hello world! 1Hello world! 2Hello world! 3Hello world! 4Hello world! 5
就这样了,都洗洗睡吧!!!
阅读全文
0 0
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 循环语句
- 欢迎使用CSDN-markdown编辑器
- HDU 2680-Choose the best route-最短路+超级源点
- 《循序渐进》前端学习视频教程资料汇总
- Android --- Json解析
- 草稿
- 循环语句
- 42. Trapping Rain Water
- 数据结构与算法(Java描述)-17、递归转化成非递归算法以及迷宫算法
- 递归公式时间复杂度举例
- File Permissions and the chmod/chgrp/chown commands
- Ubuntu14.04+NVIDIA GTX 1050ti+cuda8安装
- Jzoj4791 矩阵
- Week5Day3
- 【Matlab】处理图像