读书人

python 循环和数目字

发布时间: 2012-06-26 10:04:13 作者: rapoo

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

读书人网 >perl python

热点推荐