###### python的循环，pass和DocString

while循环和C的相似性更高：

while 1>0:
guess=int(input('enter a number: '))
if guess==23:
print 'guess right!'
break
elif guess>23:
print 'higher'
else :
print 'lower'
print 'the loop1 is over'

for i in range(1,10,3): # equal to C: for(int i=1;i<10;i+=2)
print i
else: # else statement can follow loop
print 'the loop2 is over'


>>>
enter a number: 2
lower
enter a number: 44
higher
enter a number: 23
guess right!
the loop1 is over
1
4
7
the loop2 is over
>>> 

pass在python函数中代表不返回值，或者说是返回None，类似于C的return ;

def maxnum(a,b):
if a>b:  return a
else : pass  #return none statement
print maxnum(23,45)
print maxnum(45,23)

>>>
None
45
>>> 

def midfind(a,lx,rx,goal):
''' this is a half find for ourneed number,
the return is goal number's place.'''

low=lx
high=rx
while low<=high:
mid=(low+high)>>1
if a[mid]>goal:
high=mid-1
elif a[mid]<goal:
low=mid+1
else: return mid
return -1
a=[3,5,7,10,23,45]
print midfind(a,0,5,5)+1
print (midfind.__doc__) #midfind.__doc__ is the document strings,
#note: multi-line for __

>>>
2
this is a half find for ourneed number,
the return is goal number's place.
>>>


#### Python中的循环以及break/continue/else/pass

2016-08-03 15:44:52

#### Python While 循环语句、pass 语句

2018-03-09 19:03:28

#### python for循环的一些情况。

2017-02-27 16:19:30

#### Python中的循环for和while

2016-10-22 13:56:31

#### python的continue和pass的区别

2017-10-06 14:13:05

#### continue和pass测试

2015-12-18 14:14:34

#### while循环的用法

2016-12-02 17:39:07

#### 循环神经网络

2017-05-08 11:02:52

#### 飘逸的python - 代码即文档docstring

2015-07-10 14:05:31

#### Python docstring文档字符串

2012-10-27 06:10:56

## 不良信息举报

python的循环，pass和DocString