Function Basics
返回
A First Example: Definitions and Calls
>>> def times(x,y):
... return x * y
...
>>> times(3,4)
12
>>> x = times(3.14,4)
>>> x
12.56
>>> times('Nihao', 4)
'NihaoNihaoNihaoNihao'
>>>
Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def intersect(seq1, seq2):
... res = []
... for x in seq1:
... if x in seq2:
... res.append(x)
... return res
...
>>> s1 = "SPAM"
>>> s2 = "SCAM"
>>> intersect(s1,s2)
['S', 'A', 'M']
>>> x = intersect([1,2,3],(1,4,8))
>>> x
[1]
>>>
返回
瑞丽市|
海淀区|
沈丘县|
龙井市|
定安县|
大厂|
大方县|
沽源县|
广河县|
康马县|
安庆市|
大田县|
梓潼县|
涞水县|
西平县|
宜黄县|
望奎县|
孙吴县|
塔河县|
综艺|
吉林省|
滕州市|
丰县|
藁城市|
东乌珠穆沁旗|
谢通门县|
甘泉县|
资中县|
石首市|
和静县|
万源市|
伊川县|
桃园县|
宜城市|
唐山市|
涟水县|
会东县|
临泉县|
灵武市|
苏尼特左旗|
秀山|