| [ Web Proxy ] |
| Viewing: https://wiki.python.org/moin/../python/platforms/Admin/../MacPython/../../archive/PythonSites.html | [Back] [Original] |
Legacy Wiki Page
This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.
Email: <blueelwang@gmail.com>
pythonpython
pythonpython2 python3 pythonpython3python2python2python3
1.
Py3.0 pystone benchmarkPy2.530%GuidoPy3.0
Py3.1Py2.515%
2.
Py3.Xutf-8
>>> = china >>>print() china
3.
1<>!=
2repr()
3as withTrue,False,None
4//
5nonlocalnoclocal x
6printprint() execexec()
2.X: print The answer is, 2*2 3.X: print(The answer is, 2*2) 2.X: print x, # 3.X: print(x, end= ) # 2.X: print # 3.X: print() #
2.X: print >>sys.stderr, fatal error 3.X: print(fatal error, file=sys.stderr) 2.X: print (x, y) # repr((x, y)) 3.X: print((x, y)) # print(x, y)!
7x<yxyTypeError bool
8raw_inputinput
2.X:guess = int(raw_input(Enter an integer : )) # 3.X:guess = int(input(Enter an integer : ))
9def(a, (b, c)):pass
108oct()
2.X
>>> 0666 438 >>> oct(438) 0666
3.X
>>> 0666 SyntaxError: invalid token (<pyshell#63>, line 1) >>> 0o666 438 >>> oct(438) 0o666
11 2bin()
>>> bin(438) 0b110110110 >>> _438 = 0b110110110 >>> _438 0b110110110
12Py3.X a, b, *rest = seq *rest, a = seqrestlist
seq
13super()super()
>>> class C(object):
def init:
print(C, a)
>>> class D(C):
def [init(self, a): ]
[super().]init[(a) # super() ]
[>>> D(8) C 8 ] [<]main[.D object at 0x00D7ED90> ]
[14metaclass ]
[class Foo(*bases, **kwds): . pass ]
[15class decoratordecorator ]
[>>> def foo(cls_a): ]
[def print_func(self): . print(Hello, world!) ]
cls_a.print = print_func return cls_a
[>>> @foo class C(object): ]
[pass ]
[>>> C().print() Hello, world! ]
[class decoratorPEP 3129 ]
[4. ]
[1str2.xunicode ]
[22 ]
[5. ]
[1Py3.Xlongint2.Xlong ]
[2bytes2.Xbytes ]
[>>> b = bchina ] [>>> type(b) ] [<type bytes> ]
[strbytes.encode() (str -> bytes) or .decode() (bytes -> str) ]
[>>> s = b.decode() ] [>>> s china ] [>>> b1 = s.encode() ] [>>> b1 bchina ]
[3dict.keys().items .values()iterkeys() ]
[dict.has_key() in ]
[6. ]
[1Abstraact Base ClassesABCs ]
[2ABCscellectionsPy2.5 ]
[>>> import collections ] [>>> print(\n.join(dir(collections))) Callable Container Hashable ] [ItemsView Iterable Iterator ] [KeysView Mapping ] [MappingView ] [MutableMapping ] [MutableSequence ] [MutableSet ] [NamedTuple Sequence Set Sized ] [ValuesView ] all[ ] builtins[ ] doc[ ] file[ ] name[ _abcoll _itemgetter _sys defaultdict deque ]
[ABCs PEP 3119PEP 3141 ]
[3next()]next[()next()]next[() ]
[4@abstractmethod @abstractproperty decorator ]
[7. ]
[1 BaseExceptionStardardError ]
[2.message ]
[3 raise Exception(args) raise Exception, args ]
[4asPy2.5 ]
[>>> try: ]
[.. raise NotImplementedError(Error) ]
[.. except NotImplementedError, error: ]
[.. print error.message ]
[.. Error ]
[Py3.0 ]
[>>> try: ]
[raise NotImplementedError(Error) ]
[except NotImplementedError as error: # as ]
[print(str(error)) ]
[Error ]
[5]context[3.0a1 ]
[8. ]
[1cPicklepickle ]
[2imageop ]
[3 audiodev, Bastion, bsddb185, exceptions, linuxaudiodev, md5, MimeWriter, mimify, popen2, ]
[rexec, sets, sha, stringold, strop, sunaudiodev, timingxmllib ]
[4bsddb(http://www.jcea.es/programacion/pybsddb.htm) ]
[5new ]
[6os.tmpnam()os.tmpfile()tmpfile ]
[7tokenizebytesgenerate_tokens tokenize.tokenize() ]
[9. ]
[1xrange() range()range()list ]
[>>> list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ]
[2byteshash b.lower()b.strip()b.split() b.strip(b ]
[\n\t\r \f)b.split(b ) ]
[3zip()map()filter()apply() callable()coerce() execfile()reduce()reload ]
[() ]
[hasattr() callable(). hasattr()hasattr(string, ]name[) ]
[4string.letters.lowercase.uppercasestring.ascii_letters ]
[5x < yTypeError2.x ]
[6]getslice[a[i:j]a.]getitem[(slice(I, j)) ]setitem[ ]
delitem[ ]
[7filePy2.5 ]
[>>> file ] [<type file> ]
[Py3.X ]
[>>> file Traceback (most recent call last): ] [File <pyshell#120>, line 1, in <module> ]
[file ]
[ CategoryHomepage ]
Back to top2026, Python Software Foundation
Made with Sphinx and Shibuya theme.
| Web Proxy Viewer | New URL | Original Page |