摘要: 字典是python唯一的影射类型 hash >>> brand = ['李宁', '耐克', '阿迪达斯'] >>> slogan = ['一切皆有可能', 'Just do it','Impossible is nothing'] >>> print('李宁的口号是:',slogan[brand. 阅读全文
posted @ 2017-09-08 23:04 110528844 阅读(588) 评论(0) 推荐(0) 编辑
摘要: 递归是神马 >>> def recursion(): ... recursion() ... >>> recursion() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", 阅读全文
posted @ 2017-09-07 20:35 110528844 阅读(351) 评论(0) 推荐(0) 编辑
摘要: python 允许使用lambda表达式来创建匿名函数 lambda表达式 >>> def ds(x): ... return 2 * x +1 ... >>> ds(5) 11 >>> lambda x : 2* x +1 <function <lambda> at 0x7f5f41b05d90> 阅读全文
posted @ 2017-09-07 18:43 110528844 阅读(407) 评论(0) 推荐(0) 编辑
摘要: 内嵌函数/内部函数 >>> def fun1(): ... print('fun1()正在调用') ... def fun2(): ... print('fun2()正在被调用') ... fun2() ... >>> fun1() fun1()正在调用 fun2()正在被调用 内部函数作用域在外部 阅读全文
posted @ 2017-09-07 18:10 110528844 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 过程(procedure)是简单/特殊并且没有返回值的 函数 有返回值 python 严格来说只有函数没有过程 >>> def hello(): ... print('Hello Junjie!') ... >>> temp = hello() Hello Junjie! >>> temp >>> 阅读全文
posted @ 2017-09-07 17:06 110528844 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 为了使程序代码更为简单,我们需要把程序分为越来越小的部分 对象 函数 模块 创建函数 >>> def myFirstFunction(): ... print('这是我创建的第一个函数') ... print('感觉不错,继续继续') ... >>> myFirstFunction() 这是我创建的 阅读全文
posted @ 2017-09-07 15:10 110528844 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 列表 元组和字符串的共同点 通称为序列 都可以通过所以索引得到每一个元素 默认索引值总是从0开始 可以通过分片的方法得到一个范围内的元素的集合 >>> tuple1 = (1,2,4,5,6) >>> numbers.append('a') >>> numbers [1, 18, 42, -19, 阅读全文
posted @ 2017-09-07 14:43 110528844 阅读(179) 评论(0) 推荐(0) 编辑
摘要: replacement 位置参数 >>> '{0} love {1}.{2}'.format('I', 'junjie','com') 'I love junjie.com' 关键字参数 >>> '{a} love {b}.{c}'.format(a='I', b='junjie', c='com' 阅读全文
posted @ 2017-09-06 00:32 110528844 阅读(182) 评论(0) 推荐(0) 编辑
摘要: python没有字符类型 单独一个字符就是字符串长度为1的字符串 字符串一旦定义就不能修改 >>> str1 = 'I love junjie.com' >>> str1[:6] 'I love' >>> str1 'I love junjie.com' >>> str1[5] 子字符串 'e' > 阅读全文
posted @ 2017-09-02 12:15 110528844 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 元组:戴上了枷锁的列表 由于是列表是近亲关系,所以元组和列表在实际使用上非常相似的 通过谈论元组和列表有什么不同来学习元组 主要从以下几个点来讨论学习: 创建和访问一个元组 更新和删除一个元组 元组相关的操作符 >>> tuple1 = (1, 2, 3, 4, 5, 6, 7, 7) >>> tu 阅读全文
posted @ 2017-09-01 12:26 110528844 阅读(140) 评论(0) 推荐(0) 编辑