摘要: 一、函数导入 1、为模块提供别名 >>> import math as foobar #设置math 别名为foobar >>> foobar.sqrt(4) 显示:2.0 2、为函数提供别名 >>> from math import sqrt as foobar >>> foobar(4) 显示: 阅读全文
posted @ 2016-05-26 17:20 xiaofoyuan 阅读(319) 评论(0) 推荐(0) 编辑
摘要: 一、创建和使用字典 1、创建字典 phonebook={'Alice':'2341','Beth':'9102','Cecil':'3258'} 2、dict,通过映射创建字典 >>> items=[('name','Gumby'),('age',34)] >>> d=dict(items) >>> 阅读全文
posted @ 2016-05-26 15:17 xiaofoyuan 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 一、字符串格式化 >>> format="Hello,%s. %s enough for ya?" >>> values=('World','Hot') >>> print(format % values) 显示:Hello,World. Hot enough for ya? 注:%,字符串格式化的 阅读全文
posted @ 2016-05-26 10:26 xiaofoyuan 阅读(144) 评论(0) 推荐(0) 编辑