Python 一些内置函数的总结~~~~
2024-08-26 22:41:30
1. type()
两种用法
a. 当传入参数为一个时,返回值为参数的类型
b. 当传入参数为三个时,type(name, bases, dict)
name: 类名
bases: 继承父类的元组,可继承也可不继承
dict: 构成类属性和方法的键值对(方法在外部定义,直接引用).
返回一个类对象
class TestBasic(object):
@staticmethod
def parent():
print "this is parent method" def child(self):
print "this is child method" test_property = {"name": "heihei", "child": child} Test = type("Test", (TestBasic,), test_property) test = Test() print test.name
test.child()
test.parent()
运行结果:
heihei
this is child method
this is parent method
2. reduce()
函数将一个数据集合(链表,元组等)中的所有数据进行下列操作:用传给 reduce 中的函数 function(有两个参数)先对集合中的第 1、2 个元素进行操作,得到的结果再与第三个数据用 function 函数运算,最后得到一个结果。
reduce(function, iterable[, initializer])
参数:
- function -- 函数,有两个参数
- iterable -- 可迭代对象
- initializer -- 可选,初始参数
最新文章
- web前端笔试选择题
- Codeforces Round #361 (Div. 2) B
- [转]理解HTTP幂等性
- HBase之show table
- LeetCode 【235. Lowest Common Ancestor of a Binary Search Tree】
- Java历史版本下载
- 树状数组的笔记√(hzwer blog)
- 页面上动态编译及执行java代码
- C++变量(C++变量定义、变量赋值、命名规则)
- MAC 命令行工具(Command Line Tools)安装
- 在win7/8/10鼠标右键添加“管理员取得所有权”
- Struts2框架(8)---Struts2的输入校验
- linux 基本使用命令
- haroopad 預覽區樣式
- (转)nginx uwsgi wsgi django 这些东西究竟是什么关系
- 从数据库中修改zabbix的验证方式 0 内置 1 LDAP 2 HTTP
- 页面滚动插件 better-scroll 的用法
- JDBC实例--工具类升级,使用Apache DBCP连接池重构DBUtility,让连接数据库更有效,更安全
- js简单正则表达式验证密码
- 北京Uber优步司机奖励政策(12月29日)
热门文章
- STM32---喜提点灯
- Win10安装Oracle Database 18c (18.3)
- 怎么改变wampserver默认的网站目录
- axios ajax框架 请求配置
- Win10利用CodeBlocks搭建Objective-C开发环境(一)
- console.log()和alert()的区别
- Appium移动自动化测试-----(七)Desired Capabilities
- synchrnized 和lock的区别
- Mysql 千万数据快速导入
- LeetCode 21. 合并两个有序链表(Merge Two Sorted Lists)