python部落之python刷题宝之基础知识
2016-05-19 19:05
513 查看
1
any(iterable)->bool 迭代器对象中只要有一个为True,返回结果为True。
all(iterable)->bool 迭代器对象中都为True时,返回结果才为True。
Answer: True, False
2
basestring)等价于isinstance(obj, (str, unicode));
Answer: True
3
a = bin(5) print a 得到 a = '0b101'. '0b'表示二进制表示,‘101’为正数5的二进制表示。因为返回类型为string,故len()后得到为5.
Answer:5
4
true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); class instances are callable if they have a __call__() method.
5 cmp(2,3)
比较。 cmp(x,y)->integer. 如果x<y,返回-1,如果x==y,返回0,如果x>y,返回1.
6 complex(2,3)==complex('2+3j')
True。 complex()可以接受string对象。
7 dir(arg) 返回对应arg如class的变量和方法。
8 填空,如下表达式等价于(a//b, a%b)。 _(a,b)
Answer: divmod divmod(x,y)-> (quotient,remainder) 返回元组。
any([True,False,True]), all([True,False,True])
any(iterable)->bool 迭代器对象中只要有一个为True,返回结果为True。
all(iterable)->bool 迭代器对象中都为True时,返回结果才为True。
Answer: True, False
2
isinstance(u'我‘,basestring)isinstance(object, classinfo)等同于java中的的 instanceOf.
isinstance(object, class-or-type-or-tuple) -> bool Return whether an object is an instance of a class or of a subclass thereof. With a type as second argument, return whether that is the object's type. The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for isinstance(x, A) or isinstance(x, B) or ... (etc.).而basestring是str和unicode的超类(父类),也是抽象类,因此不能被调用和实例化,但可以被用来判断一个对象是否为str或者unicode的实例,isinstance(obj,
basestring)等价于isinstance(obj, (str, unicode));
Answer: True
3
len(bin(5))bin()函数用法 bin(number)-> string. 返回整型(integer)或长整型(long)的二进制表示,返回类型为字符串。
a = bin(5) print a 得到 a = '0b101'. '0b'表示二进制表示,‘101’为正数5的二进制表示。因为返回类型为string,故len()后得到为5.
Answer:5
4
表达式 callable(1) 的值为?callable() 检查对象是否可用。Return True if the object argument appears callable, False if not. If this returns
true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); class instances are callable if they have a __call__() method.
5 cmp(2,3)
比较。 cmp(x,y)->integer. 如果x<y,返回-1,如果x==y,返回0,如果x>y,返回1.
6 complex(2,3)==complex('2+3j')
True。 complex()可以接受string对象。
7 dir(arg) 返回对应arg如class的变量和方法。
8 填空,如下表达式等价于(a//b, a%b)。 _(a,b)
Answer: divmod divmod(x,y)-> (quotient,remainder) 返回元组。
相关文章推荐
- Python测试框架doctest
- python数据类型和变量
- python的I/O
- 第一个python小程序
- Python函数常用方法
- 安装python
- Python Tensorflow下的Word2Vec代码解释
- python 实现终端中的进度条
- Python 之 sklearn 交叉验证 数据拆分
- 基于Flask的博客系统搭建
- Python学习笔记—PyQuery库的使用总结
- Python 装饰器
- 量化投资策略:常见的几种Python回测框架(库)
- python通过colorama模块在控制台输出彩色文字的方法
- Python实现C代码统计工具(一)
- python数据分析4:双色球 两个红和蓝球哪组合比例高
- python字典操作
- python:在Django项目中使用Celery实现定时任务--简单版
- Python 面向对象(二)—— 获取对象信息
- python基础-enumerate函数和python-运算符