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] >>>
返回
河北省| 会泽县| 喜德县| 昭平县| 锦州市| 泊头市| 峨眉山市| 连平县| 兴义市| 扎兰屯市| 元谋县| 张家界市| 新和县| 玛多县| 长宁县| 普兰县| 泰兴市| 镶黄旗| 福安市| 张掖市| 枣阳市| 孙吴县| 封开县| 汕头市| 九龙县| 乳山市| 安化县| 巴青县| 合阳县| 云浮市| 固原市| 商水县| 仁化县| 神农架林区| 浦县| 永城市| 阜新市| 白山市| 洞头县| 莱芜市| 外汇|