上一页 1 2 3 4 5 6 7 8 9 10 ··· 43 下一页
摘要: 文件和素材 1 打开文件 打开文件的语法: Open(name[,mode[,buffering]]) Name 文件名 Mode 模式 Buffering 缓冲参数 示例代码如下: >>> f=open(r'C:\log.txt') #文件不存在 >>> f=open(r'C:... 阅读全文
posted @ 2016-10-11 08:56 retacn_yue 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 第四章 模块 引用外部模块 Import math Math.sin(0) 自定义模块的导入 #hello.py 文件的保存位置是D:\workspace_python Print(‘hello world!’) #添加到环境变量中 Import Sys.path.append(‘D... 阅读全文
posted @ 2016-10-11 08:55 retacn_yue 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 第九章 魔法方法 属性和迭代器 构造方法,示例代码如下: >>>class FooBar: def __init__(self): self.somevar=42 >>>f=FooBar() >>>f.somev... 阅读全文
posted @ 2016-08-22 11:58 retacn_yue 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 第八章 异常 Python中使用异常对象来表示异常情况 >>> 1/0 Traceback (most recent call last): File"", line 1, in 1/0 ZeroDivisionError: division by zero 自定义异常... 阅读全文
posted @ 2016-08-22 11:57 retacn_yue 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 更加抽像 对象的魔力 多态 polymorphism Def (x,y): Return x+y Add(1,2) 3 封装 encapsulation 继承 inheritance 类和类型 创建自已的类 >>>class Person: #使用 s... 阅读全文
posted @ 2016-08-22 11:56 retacn_yue 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 第四章 抽象 懒惰即美德 抽象和结构 创建函数,示例代码如下: 检查函数是否可以调用: Hasattr(func,__call__) >>> def hello(name): return 'hello,'+name+'!' >>> print (hello('re... 阅读全文
posted @ 2016-08-22 11:55 retacn_yue 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 第五章 条件 循环和其他语句 Print 和import 的更多信息 使用逗号输出 >>> print('age:',32) age: 32 两条打印语句在同一行输出: >>> name='retacn' >>> saluation='mr.' >>> greeting='hello' >>... 阅读全文
posted @ 2016-08-22 11:55 retacn_yue 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 第四章 字典:当索引不好时 字典的使用,示例代码如下: #创建字典 >>> names=['alice','beth','cecli','dee-dee','earl'] >>>numbers=['2341','9102','3158','0142','5551'] >>>numbers[na... 阅读全文
posted @ 2016-08-22 11:52 retacn_yue 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 第三章 使用字符串 1 字符串基本操作 (字符串是不可变的) 索引 分片 乘法 判断成员资格 求长度 取最小值和最大值 2 字符串格式化(精简) 示例代码如下: >>> format="hello %s %senough for ya?" >>> values=('world','hot') ... 阅读全文
posted @ 2016-08-22 11:51 retacn_yue 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 第一章 列表和元组 2.1 python的六种内建序列:列表,元组,字符串,unicode字符串,buffer对像,xrange对象 注:列表可以修改,元组不可以 >>> retacn=['retacn',30] >>> yue=['yue',32] >>> database... 阅读全文
posted @ 2016-08-22 11:50 retacn_yue 阅读(154) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 43 下一页