Python入门的36个例子——17 Return
# 017
def lifeIsAMirror():
string = raw_input()
if string == 'I love you!':
return 'I love you, too!'
elif string == 'Fuck you!':
return ''
else:
return
# end of def
string = lifeIsAMirror()
if len(string) == 0:
print 'You have nothing.'
else:
print string
# end of if
output:
1
2
3
4
5
6
>>>
Fuck you!
You have nothing.
>>>
I love you!
I love you, too!
相关文档:
import time,thread
def test(a,b):
for i in range(a,b):
time.sleep(1)
print i
def start():
thread.start_new_thread(test,(1,1001))
thread.start_new_thread(test,(1000,2001))
if __name__=='__main__':
start()
......
1. Basic
参考《Python正则表达式操作指南》
模块re,perl风格的正则表达式
regex并不能解决所有的问题,有时候还是需要代码
regex基于确定性和非确定性有限自动机
2. 字符匹配(循序渐进)
元字符
. ^ $ * + ? { [ ] \ | ( )
1) "[" 和 "]"常用来指定一个字符类别,所谓字符类别就是你想匹配的一个字符集。如[ ......
关于C++和Python之间互相调用的问题,可以查找到很多资料。本文将主要从解决实际问题的角度看如何构建一个Python和C++混合系统。
&nbs ......