python Flashcards

1
Q

Tornado

A

一个异步web服务器

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

break

A

用来终止循环语句

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

continue

A

跳过当前循环块中的剩余语句

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

序列

A

列表、元组和字符串都是序列,序列的两个主要特点是索引操作符和切片操作符。索引操作符让我们可以从序列中抓取一个特定项目。切片操作符让我们能够获取序列的一个切片,即一部分序列

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

exec

A

用来执行储存在字符串或文件中的Python语句。例如

> > > exec ‘print “Hello World”’
Hello World

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

eval

A

用来计算存储在字符串中的有效Python表达式。例如

> > > eval(‘2*3’)
6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

文档字符串

A

通常被简称为 docstrings。
在函数的第一个逻辑行的字符串是这个函数的 文档字符串
DocStrings也适用于模块和类。
文档字符串的惯例是一个多行字符串,它的首行以大写字母开始,句号结尾。第二行是空行,从第三行开始是详细的描述。

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

abs(x)

A

Return the absolute value of a number. The argument may be a plain or long integer or a floating point number. If the argument is a complex number, its magnitude is returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

all(iterable)

A

Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to:

def all(iterable):
    for element in iterable:
        if not element:
            return False
    return True
New in version 2.5.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

any(iterable)

A

Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to:

def any(iterable):
    for element in iterable:
        if element:
            return True
    return False
New in version 2.5.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

basestring

A
This abstract type is the superclass for str and unicode. It cannot be called or instantiated, but it can be used to test whether an object is an instance of str or unicode. isinstance(obj, basestring) is equivalent to isinstance(obj, (str, unicode)).
New in version 2.3.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

bin(x)

A

Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

bool([x])

A
Convert a value to a Boolean, using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.
If no argument is given, this function returns False.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

callable(object)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

chr(i)

A

Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string ‘a’. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range. See also unichr().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

classmethod(function)

A

Return a class method for function.

A class method receives the class as implicit first argument, just like an instance method receives the instance. 
The @classmethod form is a function decorator
It can be called either on the class (such as C.f()) or on an instance (such as C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

cmp(x, y)

A

Compare the two objects x and y and return an integer according to the outcome. The return value is negative if x < y, zero if x == y and strictly positive if x > y.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

compile(source, filename, mode[, flags[, dont_inherit]])

A

Compile the source into a code or AST object. Code objects can be executed by an exec statement or evaluated by a call to eval(). source can either be a string or an AST object. Refer to the ast module documentation for information on how to work with AST objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

complex([real[, imag]])

A

Create a complex number with the value real + imag*j or convert a string or number to a complex number. If the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. The second parameter can never be a string. Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the function serves as a numeric conversion function like int(), long() and float(). If both arguments are omitted, returns 0j.

The complex type is described in Numeric Types — int, float, long, complex.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

delattr(object, name)

A

This is a relative of setattr(). The arguments are an object and a string. The string must be the name of one of the object’s attributes. The function deletes the named attribute, provided the object allows it. For example, delattr(x, ‘foobar’) is equivalent to del x.foobar.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

dict([arg])

A

Create a new data dictionary, optionally with items taken from arg.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

dir([object])

A

Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.
If the object has a method named __dir__(), this method will be called and must return the list of attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

divmod(a, b)

A

Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division. With mixed operand types, the rules for binary arithmetic operators apply. For plain and long integers, the result is the same as (a // b, a % b). For floating point numbers the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that. In any case q * b + a % b is very close to a, if a % b is non-zero it has the same sign as b, and 0 <= abs(a % b) < abs(b).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

enumerate(sequence[, start=0])

A

Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration.
For example:
»> for i, season in enumerate([‘Spring’, ‘Summer’, ‘Fall’, ‘Winter’]):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

eval(expression[, globals[, locals]])

A

The arguments are a string and optional globals and locals. If provided, globals must be a dictionary. If provided, locals can be any mapping object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

execfile(filename[, globals[, locals]])

A

This function is similar to the exec statement, but parses a file instead of a string. It is different from the import statement in that it does not use the module administration — it reads the file unconditionally and does not create a new module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

定义import *的范围

A

如果有定义__all__=[“对象名”]则只导入指定的对象 ,否则全部

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

file(filename[, mode[, bufsize]])

A

Constructor function for the file type, described further in section File Objects. The constructor’s arguments are the same as those of the open() built-in function described below.

When opening a file, it’s preferable to use open() instead of invoking this constructor directly. file is more suited to type testing (for example, writing isinstance(f, file)).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

filter(function, iterable)

A

Construct a list from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If iterable is a string or a tuple, the result also has that type; otherwise it is always a list. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

float([x])

A

Convert a string or a number to floating point.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

format(value[, format_spec])

A
Convert a value to a “formatted” representation, as controlled by format_spec.
Note format(value, format_spec) merely calls value.\_\_format\_\_(format_spec).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

frozenset([iterable])

A

Return a frozenset object, optionally with elements taken from iterable. The frozenset type is described in Set Types — set, frozenset.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

getattr(object, name[, default])

A

Return the value of the named attributed of object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

globals()

A

Return a dictionary representing the current global symbol table. This is always the dictionary of the current module (inside a function or method, this is the module where it is defined, not the module from which it is called).

35
Q

hasattr(object, name)

A

The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an exception or not.)

36
Q

hash(object)

A

Return the hash value of the object (if it has one). Hash values are integers. Numer values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).

37
Q

help([object])

A

Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.

This function is added to the built-in namespace by the site module.

New in version 2.2.

38
Q

hex(x)

A

Convert an integer number (of any size) to a hexadecimal string. The result is a valid Python expression.
Note To obtain a hexadecimal string representation for a float, use the float.hex() method.
Changed in version 2.4: Formerly only returned an unsigned literal.

39
Q

id(object)

A

Return the “identity” of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.

CPython implementation detail: This is the address of the object.

40
Q

input([prompt])

A

Equivalent to eval(raw_input(prompt)).

Warning This function is not safe from user errors! 
If the readline module was loaded, then input() will use it to provide elaborate line editing and history features.
Consider using the raw_input() function for general input from users.
41
Q

int([x[, base]])

A

Convert a string or number to a plain integer.

42
Q

isinstance(object, classinfo)

A

Return true if the object argument is an instance of the classinfo argument, or of a (direct or indirect) subclass thereof.

43
Q

issubclass(class, classinfo)

A

Return true if class is a subclass (direct or indirect) of classinfo.

44
Q

iter(o[, sentinel])

A

Return an iterator object. Without a second argument, o must be a collection object which supports the iteration protocol (the __iter__() method), or it must support the sequence protocol (the __getitem__() method with integer arguments starting at 0). If the second argument, sentinel, is given, then o must be a callable object. The iterator created in this case will call o with no arguments for each call to its next() method; if the value returned is equal to sentinel, StopIteration will be raised, otherwise the value will be returned.

One useful application of the second form of iter() is to read lines of a file until a certain line is reached. The following example reads a file until “STOP” is reached:

with open(“mydata.txt”) as fp:
for line in iter(fp.readline, “STOP”):
process_line(line)

45
Q

len(s)

A

Return the length (the number of items) of an object. The argument may be a sequence (string, tuple or list) or a mapping (dictionary).

46
Q

list([iterable])

A

Return a list whose items are the same and in the same order as iterable‘s items.

47
Q

locals()

A

Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks.

48
Q

long([x[, base]])

A

Convert a string or number to a long integer.

49
Q

map(function, iterable, …)

A

Apply function to every item of iterable and return a list of the results.

50
Q

max(iterable[, args…][key])

A

max(iterable[, args…][key])
With a single argument iterable, return the largest item of a non-empty iterable (such as a string, tuple or list). With more than one argument, return the largest of the arguments.

The optional key argument specifies a one-argument ordering function like that used for list.sort(). The key argument, if supplied, must be in keyword form (for example, max(a,b,c,key=func)).

51
Q

min(iterable[, args…][key])

A

With a single argument iterable, return the smallest item of a non-empty iterable (such as a string, tuple or list). With more than one argument, return the smallest of the arguments.

The optional key argument specifies a one-argument ordering function like that used for list.sort(). The key argument, if supplied, must be in keyword form (for example, min(a,b,c,key=func)).

52
Q

next(iterator[, default])

A

Retrieve the next item from the iterator by calling its next() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised.

53
Q

object()

A

Return a new featureless object. object is a base for all new style classes. It has the methods that are common to all instances of new style classes.

54
Q

oct(x)

A

Convert an integer number (of any size) to an octal string. The result is a valid Python expression.

55
Q

open(filename[, mode[, bufsize]])

A

open(filename[, mode[, bufsize]])
Open a file, returning an object of the file type described in section File Objects. If the file cannot be opened, IOError is raised. When opening a file, it’s preferable to use open() instead of invoking the file constructor directly.

56
Q

ord(c)

A

Given a string of length one, return an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string. For example, ord(‘a’) returns the integer 97, ord(u’\u2020’) returns 8224.

57
Q

pow(x, y[, z])

A

Return x to the power y

58
Q

print([object, …][, sep=’ ‘][, end=’\n’][, file=sys.stdout])

A

Print object(s) to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

59
Q

property([fget[, fset[, fdel[, doc]]]])

A

Return a property attribute for new-style classes (classes that derive from object).

60
Q

range([start], stop[, step])

A

This is a versatile function to create lists containing arithmetic progressions.

61
Q

raw_input([prompt])

A

If the prompt argument is present, it is written to standard output without a trailing newline.

62
Q

reduce(function, iterable[, initializer])

A

Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). The left argument, x, is the accumulated value and the right argument, y, is the update value from the iterable. If the optional initializer is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty. If initializer is not given and iterable contains only one item, the first item is returned.

63
Q

reload(module)

A

Reload a previously imported module.

64
Q

repr(object)

A

Return a string containing a printable representation of an object. function returns for its instances by defining a __repr__() method.

65
Q

reversed(seq)

A

Return a reverse iterator. seq must be an object which has a __reversed__() method or supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0).

66
Q

round(x[, n])

A

Return the floating point value x rounded to n digits after the decimal point.

67
Q

set([iterable])

A

Return a new set, optionally with elements taken from iterable. The set type is described in Set Types — set, frozenset.

68
Q

setattr(object, name, value)

A

The function assigns the value to the attribute, provided the object allows it.

69
Q

slice([start], stop[, step])

A

Return a slice object representing the set of indices specified by range(start, stop, step).

70
Q

sorted(iterable[, cmp[, key[, reverse]]])

A

Return a new sorted list from the items in iterable.

71
Q

staticmethod(function)

A

Return a static method for function.

72
Q

str([object])

A

Return a string containing a nicely printable representation of an object.

73
Q

sum(iterable[, start])

A

Sums start and the items of an iterable from left to right and returns the total.

74
Q

super(type[, object-or-type])

A

Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class.

75
Q

tuple([iterable])

A

Return a tuple whose items are the same and in the same order as iterable‘s items.

76
Q

type(object)

A

Return the type of an object. The return value is a type object. The isinstance() built-in function is recommended for testing the type of an object.

77
Q

type(name, bases, dict)

A
Return a new type object. 
>>> class X(object):
...     a = 1
...
>>> X = type('X', (object,), dict(a=1))
78
Q

unichr(i)

A

Return the Unicode string of one character whose Unicode code is the integer i. For example, unichr(97) returns the string u’a’. This is the inverse of ord() for Unicode strings.

79
Q

unicode([object[, encoding[, errors]]])

A

Return the Unicode string version of object

80
Q

vars([object])

A
Without an argument, act like locals().
With a module, class or class instance object as argument (or anything else that has a \_\_dict\_\_ attribute), return that attribute.
81
Q

xrange([start], stop[, step])

A

This function is very similar to range(), but returns an “xrange object” instead of a list.

82
Q

zip([iterable, …])

A
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zipped)
>>> x == list(x2) and y == list(y2)
True
83
Q

apply(function, args[, keywords])

A

The use of apply() is equivalent to function(*args, **keywords).