本文摘自php中文网,作者silencement,侵删。

打印1~20之间整数的方法:
1、使用for循环
1 2 | for i in range(1,21):
print(i,end=',')
|
输出结果
1 | 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
|
2、使用while循环
1 2 3 4 | i= 1
while i <= 20:
print(i,end=',')
i += 1
|
输出结果
1 | 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
|
以上就是python如何打印1~20的整数的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python3怎么输出中文
详解yield和generators生成器
对于初学者如何理解 @classmethod 和@staticmethod
Python中类和函数的区别
Python中pop()函数如何使用
Python实现rsa算法
详解django中cookiecutter的使用教程
django框架使用mysql的教程介绍(代码示例)
介绍Python的matplotlib常用绘图函数
Python实现代码行数统计工具的功能(实例)
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python如何打印1~20的整数