奇怪的现象 在paython3中 print(range(10)) 得出的结果是 range(0,10) ,而不是[0,1,2,3,4,5,6,7,8,9] ,为什么呢? 官网原话: In many ways the object returned by range() behaves as if it is a list, but in fact it isn’t. It is an object which returns the successive items of the desire…
需求:写一个属于你自己的 frange函数,frange与range类似,一样的参数规则,但是每一项必须要是float类型 实现: 注意点,如何判断stop是否有参数传入,这里使用空字符判断,如frange(10)和frange(10,0)逻辑处理是不同的 def frange(start,stop=None,step=1): result = [] if stop==None: stop=start start=0.0 if step>=1: while start < stop: resu…
条件判断经常使用if语句进行判断,表达方式为:if 条件语句: :elif:else if...用于执行第一条不满足if的判断,继续执行其它的判断.比如一个简单的if判断 Python3取消了raw_input(),使用input()接受输入,如果需要,在input()前加上限定条件int or float,默认str不用添加. score = int(input('input your score')) if num >= 80: print("excellllent!&quo…
python中的range()函数的功能hen强大,所以我觉得很有必要和大家分享一下 就好像其API中所描述的: If you do need to iterate over a sequence of numbers, the built-in function range() comes in handy. It generates arithmetic progressions 下面是我做的demo: #如果你需要遍历一个数字序列,可以是使用python中内建的函数range() #如下面…