首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python 循环和数目字

2012-06-26 
python 循环和数字http://www.gqtao.com/archives/37.html原题:循环和数字。分别使用while和for创建一个循

python 循环和数字
http://www.gqtao.com/archives/37.html
原题:循环和数字。
分别使用while和for创建一个循环。
(a)写一个while循环,输出整型为0~10(要确保是0~10)。
(b)做同一样的事,不过这次使用range()内建函数。
答案:
用while来做

?1234 n=0while n<=10:     print (n,end=' ')     n+=1

用for来做

?12 for n in range(11):     print(n,end=' ')

输出结果:
0 1 2 3 4 5 6 7 8 9 10

--------------------------------------
Python格式化日期时间的函数为datetime.datetime.strftime();由字符串转为日期型的函数为:datetime.datetime.strptime(),两个函数都涉及日期时间的格式化字符串

http://docs.python.org/library/datetime.html

热点排行