`
famoushz
  • 浏览: 2952329 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Python 2.5 Quick Reference

阅读更多

转载   Python 2.5 Quick Reference 收藏

<script type="text/javascript"> document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData(&quot;text&quot;); if (text &amp;&amp; text.length &gt; 300) { text = text + &quot;\r\n\n本文来自CSDN博客,转载请标明出处:&quot; + location.href; clipboardData.setData(&quot;text&quot;, text); } }, 100); } } </script><script type="text/javascript"> function StorePage() { d = document; t = d.selection ? (d.selection.type != 'None' ? d.selection.createRange().text : '') : (d.getSelection ? d.getSelection() : ''); void (keyit = window.open('http://www.365key.com/storeit.aspx?t=' + escape(d.title) + '&amp;u=' + escape(d.location.href) + '&amp;c=' + escape(t), 'keyit', 'scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes')); keyit.focus(); }</script>

Style chooser: Modern , Modern Black&White , Classic , High contrast or Printing
[Hint : Use styles Modern Black & White or Printing to print. If you get problems, try printing the PDF versions instead]

<!-- SUMMARY -->

Contents

<!-- FRONT STUFF -->

Front matter

Version 2.5 (What's new? )
Check updates at http://rgruet.free.fr/#QuickRef .
Please report errors, inaccuracies and suggestions to Richard Gruet (pqr at rgruet.net).

<!-- LICENSE CREATIVE COMMONS -->

Creative Commons License Creative Commons License.

Last modified on <!-- #BeginDate format:Am1 -->August 16, 2009<!-- #EndDate -->
14 Dec 2006,
upgraded by Richard Gruet for Python 2.5
17 Feb 2005,
upgraded by Richard Gruet for Python 2.4
03 Oct 2003,
upgraded by Richard Gruet for Python 2.3
11 May 2003, rev 4
upgraded by Richard Gruet for Python 2.2 (restyled by Andrei )
7 Aug 2001
upgraded by Simon Brunning for Python 2.1
16 May 2001
upgraded by Richard Gruet and Simon Brunning for Python 2.0
18 Jun 2000
upgraded by Richard Gruet for Python 1.5.2
30 Oct 1995
created by Chris Hoffmann for Python 1.3

Color coding:

Features added in 2.5 since 2.4
Features added in 2.4 since 2.3
Features added in 2.3 since 2.2
Features added in 2.2 since 2.1

Originally based on:

<!-- LINKS -->

Useful links :

Tip : From within the Python interpreter, type help , help(object ) or help("name ") to get help.
<!-- INVOCATION OPTIONS -->

Invocation Options

python [w ] [-dEhim OQStuUvVWxX?] [-c command | scriptFile | - ] [args ]
    (pythonw does not open a terminal/console; python does)
Invocation Options Option Effect
-d Output parser debugging information (also PYTHONDEBUG=x)
-E Ignore environment variables (such as PYTHONPATH)
-h Print a help message and exit (formerly -?)
-i Inspect interactively after running script (also PYTHONINSPECT=x) and force prompts, even if stdin appears not to be a terminal.
-m module Search for module on sys.path and runs the module as a script. (Implementation improved in 2.5: module runpy )
-O Optimize generated bytecode (also PYTHONOPTIMIZE=x). Asserts are suppressed.
-OO Remove doc-strings in addition to the -O optimizations.
-Q arg Division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
-S Don't perform import site on initialization.
-t Issue warnings about inconsistent tab usage (-tt: issue errors).
-u Unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x).
-U Force Python to interpret all string literals as Unicode literals.
-v Verbose (trace import statements) (also PYTHONVERBOSE=x).
-V Print the Python version number and exit.
-W arg Warning control (arg is action:message:category:module:lineno)
-x Skip first line of source, allowing use of non-unix Forms of #!cmd
-X Disable class based built-in exceptions (for backward compatibility management of exceptions)
-c command Specify the command to execute (see next section). This terminates the option list (following options are passed as arguments to the command).
scriptFile The name of a python file (.py) to execute. Read from stdin.
- Program read from stdin (default; interactive mode if a tty).
args Passed to script or command (in sys.argv[1:] )
  If no scriptFile or command, Python enters interactive mode.
  • Available IDEs in std distrib: IDLE (tkinter based, portable), Pythonwin (on Windows). Other free IDEs: IPython (enhanced interactive Python shell), Eric , SPE , BOA constructor , PyDev (Eclipse plugin).
  • Typical python module header :
    #!/usr/bin/env python
    # -*- coding: latin1 -*-
    Since 2.3 the encoding of a Python source file must be declared as one of the two first lines (or defaults to 7 bits Ascii ) [PEP-0263 ], with the format:
    # -*- coding: encoding -*-
    Std encodings are defined here , e.g. ISO-8859-1 (aka latin1), iso-8859-15 (latin9), UTF-8... Not all encodings supported, in particular UTF-16 is not supported.
  • It's now a syntax error if a module contains string literals with 8-bit characters but doesn't have an encoding declaration (was a warning before).
  • Since 2.5, from __future__ import feature statements must be declared at beginning of source file.
  • Site customization : File sitecustomize.py is automatically loaded by Python if it exists in the Python path (ideally located in ${PYTHONHOME}/lib/site-packages/ ).
  • Tip: when launching a Python script on Windows,
    <pythonHome>\python myScript.py args ... can be reduced to :
    myScript.py args ... if <pythonHome> is in the PATH envt variable, and further reduced to :
    myScript args ... provided that .py;.pyw;.pyc;.pyo is added to the PATHEXT envt variable.
<!-- ENVIRONMENT VARIABLES -->

Environment variables

Environment variables Variable Effect
PYTHONHOME Alternate prefix directory (or prefix ;exec_prefix ). The default module search path uses prefix /lib
PYTHONPATH Augments the default search path for module files. The format is the same as the shell's $PATH : one or more directory pathnames separated by ':' or ';' without spaces around (semi-) colons !
On Windows Python first searches for Registry key HKEY_LOCAL_MACHINE\Software\Python\PythonCore\x.y \PythonPath (default value). You can create a key named after your application with a default string value giving the root directory path of your appl.

Alternatively, you can create a text file with a .pth extension, containing the path(s), one per line, and put the file somewhere in the Python search path (ideally in the site-packages/ directory). It's better to create a .pth for each application, to make easy to uninstall them.
PYTHONSTARTUP If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode (no default).
PYTHONDEBUG If non-empty, same as -d option
PYTHONINSPECT If non-empty, same as -i option
PYTHONOPTIMIZE If non-empty, same as -O option
PYTHONUNBUFFERED If non-empty, same as -u option
PYTHONVERBOSE If non-empty, same as -v option
PYTHONCASEOK If non-empty, ignore case in file/module names (imports)
<!-- NOTABLE LEXICAL ENTITIES -->

Notable lexical entities

Keywords

        and       del       for       is        raise
        assert    elif      from      lambda    return
        break     else      global    not       try
        class     except    if        or        while
        continue  exec      import    pass      with

        def       finally   in        print     yield
  • (List of keywords available in std module: keyword )
  • Illegitimate Tokens (only valid in strings): $ ? (plus @ before 2.4)
  • A statement must all be on a single line. To break a statement over multiple lines, use "\ ", as with the C preprocessor.
    Exception : can always break when inside any (), [], or {} pair, or in triple-quoted strings.
  • More than one statement can appear on a line if they are separated with semicolons ("; ").
  • Comments start with "# " and continue to end of line.
<!-- IDENTIFIERS -->

Identifiers

(letter | "_") (letter | digit | "_")*
  • Python identifiers keywords, attributes, etc. are case-sensitive .
  • Special forms: _ ident (not imported by 'from module import *'); __ ident __ (system defined name); __ident (class-private name mangling).
<!-- STRING LITERALS -->

String literals

Two flavors: str (standard 8 bits locale-dependent strings, like ascii, iso 8859-1, utf-8, ...) and unicode (16 or 32 bits/char in utf-16 mode or 32 bits/char in utf-32 mode); one common ancestor basestring .

Literal
" a string enclosed by double quotes"
' another string delimited by single quotes and with a " inside'
''' a string containing embedded newlines and quote (') marks, can be delimited with triple quotes.'''
""" may also use 3- double quotes as delimiters """
u' a unicode string'
U" Another unicode string"
r' a raw string where \ are kept (literalized): handy for regular expressions and windows paths!'
R" another raw string"   -- raw strings cannot end with a \
ur' a unicode raw string'
UR" another raw unicode "
  • Use \ at end of line to continue a string on next line.
  • Adjacent strings are concatened, e.g. 'Monty ' 'Python' is the same as 'Monty Python' .
  • u'hello' + ' world'   --> u'hello world'    (coerced to unicode)
String Literal Escapes Escape Meaning
\newline Ignored (escape newline)
\\ Backslash (\)
\e Escape (ESC)
\v Vertical Tab (VT)
\' Single quote (')
\f Formfeed (FF)
\ ooo char with octal value ooo
\" Double quote (")
\n Linefeed (LF)
\a Bell (BEL)
\r Carriage Return (CR)
\x hh char with hex value hh
\b Backspace (BS)
\t Horizontal Tab (TAB)
\u xxxx Character with 16-bit hex value xxxx (unicode only)
\U xxxxxxxx Character with 32-bit hex value xxxxxxxx (unicode only)
\N{ name } Character named in the Unicode database (unicode only), e.g. u'\N{Greek Small Letter Pi}' <=> u'\u03c0'.
(Conversely, in module unicodedata, unicodedata.name(u'\u03c0') == 'GREEK SMALL LETTER PI' )
\AnyOtherChar left as-is, including the backslash, e.g. str('\z') == '\\z'
  • NUL byte (\000 ) is not an end-of-string marker; NULs may be embedded in strings.
  • Strings (and tuples) are immutable : they cannot be modified.
<!-- BOOLEAN CONSTANTS -->

Boolean constants (since 2.2.1)

  • True
  • False

In 2.2.1, True and False are integers 1 and 0. Since 2.3, they are of new type bool .
<!-- NUMBERS -->

Numbers

  • Decimal integer : 1234, 1234567890546378940L (or l)
  • Octal integer: 0 177, 0 177777777777777777L (begin with a 0 )
  • Hex integer: 0x FF, 0X FFFFffffFFFFFFFFFFL (begin with 0x or 0X )
  • Long integer (unlimited precision): 1234567890123456L (ends with L or l ) or long( 1234)
  • Float (double precision): 3. 14e-10 , .001, 10., 1E3
  • Complex : 1J , 2+ 3J , 4+ 5j (ends with J or j, + separates (float) real and imaginary parts)

Integers and long integers are unified starting from release 2.2 (the L suffix is no longer required)
<!-- SEQUENCES -->

Sequences

  • Strings (types str and unicode ) of length 0, 1, 2 (see above )
      '', '1', "12", 'hello\n'
  • Tuples (type tuple ) of length 0, 1, 2, etc:
      () (1, ) (1,2) # parentheses are optional if len > 0
  • Lists (type list ) of length 0, 1, 2, etc:
      [] [1] [1,2]
  • Indexing is 0 -based. Negative indices (usually) mean count backwards from end of sequence.
  • Sequence slicing [ starting-at-index : but-less-than-index [ : step] ] . Start defaults to 0, end to len(sequence), step to 1 .
      a = (0,1,2,3,4,5,6,7)
      a[3] == 3
      a[-1] == 7
      a[2:4] == (2, 3)
      a[1:] == (1, 2, 3, 4, 5, 6, 7)
      a[:3] == (0, 1, 2)
      a[:] == (0,1,2,3,4,5,6,7) # makes a copy
     of the sequence.
      a[::2] == (0, 2, 4, 6) # Only even numbers. 
      a[::-1] = (7, 6, 5, 4, 3 , 2, 1, 0) # Reverse order.
    
<!-- DICTIONARIES -->

Dictionaries (Mappings)

Dictionaries (type dict ) of length 0, 1, 2, etc: {} {1 : 'first'} {1 : 'first', 'two': 2, key :value }

Keys must be of a hashable type; Values can be any type.

<!-- OPERATORS -->

Operators and their evaluation order

Operators and their evaluation order Highest Operator Comment Lowest
  , [ ...] { ...} ` ...` Tuple, list & dict. creation; string conv.
s[ i] s[ i: j] s. attr f( ...) indexing & slicing; attributes, fct calls
+ x, - x, ~ x Unary operators
x** y Power
x* y x/ y x% y mult, division, modulo
x+ y x- y addition, substraction
x<<y   x>>y Bit shifting
x& y Bitwise and
x^ y Bitwise exclusive or
x| y Bitwise or
x< y  x<= y  x> y  x>= y  x== y x!= y  x<> y
x is y   x is not y
x in s   x not in s
Comparison, 
identity, 
membership
not x boolean negation
x and y boolean and
x or y boolean or
lambda args : expr anonymous function
  • Alternate names are defined in module operator (e.g. __add__ and add for +)
  • Most operators are overridable
<!-- BASIC TYPES AND THEIR OPERATIONS -->

Basic types and their operations

<!-- COMPARISONS -->

Comparisons (defined between any types)

Comparisons Comparison Meaning
Notes
< strictly less than
(1)
<= less than or equal to  
> strictly greater than  
>= greater than or equal to  
== equal to  
!= or <> not equal to  
is object identity
(2)
is not negated object identity
(2)

Notes :

  • Comparison behavior can be overridden for a given class by defining special method __cmp__ .
  • (1) X < Y < Z < W has expected meaning, unlike C
  • (2) Compare object identities (i.e. id (object)), not object values.
<!-- NONE -->

None

  • None is used as default return value on functions. Built-in single object with type NoneType . Might become a keyword in the future.
  • Input that evaluates to None does not print when running Python interactively.
  • None is now a constant ; trying to bind a value to the name "None" is now a syntax error.
<!-- BOOLEAN OPERATORS -->

Boolean operators

Boolean values and operators Value or Operator Evaluates to
Notes
built-in bool (expr ) True if expr is true, False otherwise.
None , numeric zeros, empty sequences and mappings considered False  
all other values considered True  
not x True if x is False , else False  
x or y if x is False then y , else x
(1)
x and y if x is False then x , else y
(1)

Notes :

  • Truth testing behavior can be overridden for a given class by defining special method __nonzero__ .
  • (1) Evaluate second arg only if necessary to determine outcome.
<!-- NUMERIC TYPES -->

Numeric types

Floats, integers, long integers, Decimals .

  • Floats (type float ) are implemented with C doubles.
  • Integers (type int ) are implemented with C longs (signed 32 bits, maximum value is sys.maxint )
  • Long integers (type long ) have unlimited size (only limit is system resources).
  • Integers and long integers are unified starting from release 2.2 (the L suffix is no longer required). int() returns a long integer instead of raising OverflowError . Overflowing operations such as 2<<32 no longer trigger FutureWarning and return a long integer.
  • Since 2.4, new type Decimal introduced (see module: decimal ) to compensate for some limitations of the floating point type, in particular with fractions. Unlike floats, decimal numbers can be represented exactly; exactness is preserved in calculations; precision is user settable via the Context type [PEP 327 ].
<!-- OPERATORS ON ALL NUMERIC TYPES -->

Operators on all numeric types

Operators on all numeric types Operation Result
abs (x ) the absolute value of x
int (x ) x converted to integer
long (x ) x converted to long integer
float (x ) x converted to floating point
-x x negated
+x x unchanged
x + y the sum of x and y
x - y difference of x and y
x * y product of x and y
x / y true division of x by y: 1/2 -> 0.5 (1)
x // y floor division operator: 1//2 -> 0 (1)
x % y x modulo y
divmod (x , y ) the tuple (x //y , x %y )
x ** y x to the power y (the same as pow (x ,y ))

Notes :

  • (1) / is still a floor division (1/2 == 0) unless validated by a from __future__ import division .
  • classes may override methods __truediv__ and __floordiv__ to redefine these operators.
<!-- BIT OPERATORS ON INTEGERS AND LONG INTEGERS -->

Bit operators on integers and long integers

Bit operators Operation Result
~x the bits of x inverted
x ^ y bitwise exclusive or of x and y
x & y bitwise and of x and y
x | y bitwise or of x and y
x << n x shifted left by n bits
x >> n x shifted right by n bits
<!-- COMPLEX NUMBERS -->

Complex Numbers

  • Type complex , represented as a pair of machine-level double precision floating point numbers.
  • The real and imaginary value of a complex number z can be retrieved through the attributes z.real and z.imag .
<!-- NUMERIC EXCEPTIONS -->

Numeric exceptions

TypeError
raised on application of arithmetic operation to non-number
OverflowError
numeric bounds exceeded
ZeroDivisionError
raised when zero second argument of div or modulo op
<!-- OPERATIONS ON ALL SEQUENCE TYPES -->

Operations on all sequence types (lists, tuples, strings)

Operations on all sequence types Operation Result
Notes
x in s True if an item of s is equal to x , else False
(3)
x not in s False if an item of s is equal to x , else True
(3)
s1 + s2 the concatenation of s1 and s2  
s * n , n * s n copies of s concatenated
 
s [ i ] i 'th item of s , origin 0
(1)
s [ i : j ]
s [ i : j : step ]
Slice of s from i (included) to j (excluded). Optional step value, possibly negative (default: 1).
(1), (2)
len (s ) Length of s  
min (s ) Smallest item of s
 
max (s ) Largest item of s
 
reversed (s ) [2.4] Returns an iterator on s in reverse order. s must be a sequence, not an iterator (use reversed(list(s)) in this case. [PEP 322]
 
sorted (iterable [, cmp ]
  [, cmp=cmpFct ]
  [, key=keyGetter ]
  [, reverse=bool ])
[2.4] works like the new in-place list.sort() , but sorts a new list created from the iterable .
 

Notes :

  • (1) if i or j is negative, the index is relative to the end of the string, ie len(s )+i or len(s )+j is substituted. But note that -0 is still 0.
  • (2) The slice of s from i to j is defined as the sequence of items with index k such that i<= k < j .
    If i or j is greater than len(s ), use len(s ). If j is omitted, use len(s ). If i is greater than or equal to j , the slice is empty.
  • (3) For strings: before 2.3, x must be a single character string; Since 2.3, x in s is True if x is a substring of s.
<!-- OPERATIONS ON MUTABLE SEQUENCES -->

Operations on mutable sequences (type list )

Operations on mutable sequences Operation Result
Notes
s [ i ] = x item i of s is replaced by x  
s [i :j [:step ] ] = t slice of s from i to j is replaced by t  
del s [i :j [:step ] ] same as s [i :j ] = []  
s .append (x ) same as s [len(s ) : len(s )] = [x ]  
s .extend (x ) same as s [len(s ):len(s )]= x
(5)
s .count (x ) returns number of i 's for which s [i ] == x  
s .index (x [, start [, stop ]] ) returns smallest i such that s [i ]==x . start and stop limit search to only part of the list.
(1)
s .insert (i , x ) same as s [i :i ] = [x ] if i >= 0. i == -1 inserts before the last element.  
s .remove (x ) same as del s [s .index(x )]
(1)
s .pop ([ i ] ) same as x = s[i]; del s[i]; return x
(4)
s .reverse () reverses the items of s in place
(3)
s .sort ([ cmp ] )
s .sort ([cmp=cmpFct ]
  [, key=keyGetter ]
  [, reverse=bool ])
sorts the items of s in place
(2), (3)

Notes :

  • (1) Raises a ValueError exception when x is not found in s (i.e. out of range).
  • (2) The sort() method takes an optional argument cmp specifying a comparison function takings 2 list items and returning -1, 0, or 1 depending on whether the 1st argument is considered smaller than, equal to, or larger than the 2nd argument. Note that this slows the sorting process down considerably. Since 2.4, the cmp argument may be specified as a keyword, and 2 optional keywords args are added: key is a fct that takes a list item and returns the key to use in the comparison (faster than cmp ); reverse : If True, reverse the sense of the comparison used.
    Since Python 2.3, the sort is guaranteed "stable". This means that two entries with equal keys will be returned in the same order as they were input. For example, you can sort a list of people by name, and then sort the list by age, resulting in a list sorted by age where people with the same age are in name-sorted order.
  • (3) The sort() and reverse() methods modify the list in place for economy of space when sorting or reversing a large list. They don't return the sorted or reversed list to remind you of this side effect.
  • (4) The pop() method is not supported by mutable sequence types other than lists. The optional argument i defaults to -1, so that by default the last item is removed and returned.
  • (5) Raises a TypeError when x is not a list object.
<!-- OPERATION ON DICTIONARIES -->

Operations on mappings / dictionaries (type dict )

Operations on mappings Operation Result
Notes
len (d ) The number of items in d  
dict ()
dict (**kwargs )
dict (iterable )
dict (d)
Creates an empty dictionary.
Creates a dictionary init with the keyword args kwargs .
Creates a dictionary init with (key, value) pairs provided by iterable .
Creates a dictionary which is a copy of dictionary d .
 
d .fromkeys (iterable , value =None) Class method to create a dictionary with keys provided by iterator , and all values set to value .  
d [ k ] The item of d with key k
(1)
d [k ] = x Set d [k ] to x  
del d [k ] Removes d [k ] from d
(1)
d .clear () Removes all items from d  
d .copy () A shallow copy of d  
d .has_key (k )
k in d
True if d has key k , else False  
d .items () A copy of d 's list of (key, item) pairs
(2)
d .keys () A copy of d 's list of keys
(2)
d1 .update (d2 ) for k, v in d2 .items(): d1 [k] = v
Since 2.4, update (**kwargs ) and update (iterable ) may also be used.
d .values () A copy of d 's list of values
(2)
d .get (k , defaultval ) The item of d with key k
(3)
d .setdefault (k [,defaultval ]) d [k ] if k in d , else defaultval (also setting it)
(4)
d.iteritems () Returns an iterator over (key, value) pairs .  
d.iterkeys () Returns an iterator over the mapping's keys .  
d.itervalues () Returns an iterator over the mapping's values .  
d .pop (k [, default ]) Removes key k and returns the corresponding value. If key is not found, default is returned if given, otherwise KeyError is raised.  
d .popitem () Removes and returns an arbitrary (key, value) pair from d
 

Notes :

  • TypeError is raised if key is not acceptable.
  • (1) KeyError is raised if key k is not in the map.
  • (2) Keys and values are listed in random order.
  • (3) Never raises an exception if k is not in the map, instead it returns defaultval . defaultval is optional, when not provided and k is not in the map, None is returned.
  • (4) Never raises an exception if k is not in the map, instead returns defaultVal , and adds k to map with value defaultVal . defaultVal is optional. When not provided and k is not in the map, None is returned and added to map.
<!-- OPERATIONS ON STRINGS -->

Operations on strings (types str & unicode )

These string methods largely (but not completely) supersede the functions available in the string module.
The str and unicode types share a common base class basestring .
Operations on strings Operation Result
Notes
s. capitalize () Returns a copy of s with its first character capitalized, and the rest of the characters lowercased.  
s. center (width [ , fillChar=' ' ] ) Returns a copy of s centered in a string of length width , surrounded by the appropriate number of fillChar characters.
(1)
s. count (sub [ , start [ , end ]] ) Returns the number of occurrences of substring sub in string s .
(2)
s. decode ( [ encoding [ , errors ]] ) Returns a unicode string representing the decoded version of str s , using the given codec (encoding). Useful when reading from a file or a I/O function that handles only str . Inverse of encode .
(3)
s. encode ( [ encoding [ , errors ]] ) Returns a str representing an encoded version of s . Mostly used to encode a unicode string to a str in order to print it or write it to a file (since these I/O functions only accept str ), e.g. u'légère'.encode('utf8') . Also used to encode a str to a str , e.g. to zip (codec 'zip') or uuencode (codec 'uu') it. Inverse of decode .
(3)
s. endswith (suffix [ , start [ , end ]] ) Returns True if s ends with the specified suffix , otherwise return false. Since 2.5 suffix can also be a tuple of strings to try.
(2)
s. expandtabs ( [ tabsize ] ) Returns a copy of s where all tab characters are expanded using spaces.
(4)
s. find (sub [ ,start [ ,end ]] ) Returns the lowest index in s where substring sub is found. Returns -1 if sub is not found.
(2)
s. index (sub [ , start [ , end ]] ) like find() , but raises ValueError when the substring is not found.
(2)
s. isalnum () Returns True if all characters in s are alphanumeric, False otherwise.
(5)
s. isalpha () Returns True if all characters in s are alphabetic, False otherwise.
(5)
s. isdigit () Returns True if all characters in s are digit characters, False otherwise.
(5)
s. islower () Returns True if all characters in s are lowercase, False otherwise.
(6)
s. isspace () Returns True if all characters in s are whitespace characters, False otherwise.
(5)
s. istitle () Returns True if string s is a titlecased string, False otherwise.
(7)
s. isupper () Returns True if all characters in s are uppercase, False otherwise.
(6)
separator. join (seq) Returns a concatenation of the strings in the sequence seq , separated by string separator , e.g.: ",".join(['A', 'B', 'C']) -> "A,B,C"
 
s. ljust/rjust/center (width [, fillChar=' ' ] ) Returns s
分享到:
评论

相关推荐

    python2.5--安装包

    安装完成后,可以通过命令行输入`python --version`或`python2.5 --version`来验证Python 2.5是否正确安装。 需要注意的是,尽管Python 2.5是一个经典版本,但它已经不再被官方维护,安全性和兼容性方面可能存在...

    python 2.5

    Python 2.5是Python编程语言的一个重要版本,发布于2006年,它引入了许多新特性,改进了已有的功能,并修复了一些错误。在这个版本中,开发者们可以享受到更强大、更高效的编程体验。以下是一些关于Python 2.5的关键...

    Python2.5教程

    Python 2.5是Python编程语言的一个重要版本,发布于2006年,它引入了许多新特性并改进了已有的功能。这个教程是专为学习和理解Python 2.5设计的,涵盖了广泛的主题,旨在帮助开发者充分利用这一版本的强大功能。 ...

    numpy免安装-python2.5

    标题中的“numpy免安装-python2.5”意味着我们将讨论如何在Python 2.5环境中无需正式安装过程就能使用NumPy库。NumPy是Python科学计算的核心库,提供了大量的数学和逻辑操作功能,尤其对于处理多维数组和矩阵非常...

    wxPython2.8 for python2.5

    "wxPython2.8 for python2.5" 这个标题表明我们正在讨论的是一个针对Python 2.5版本的wxPython库的特定构建,版本号为2.8。wxPython是一个流行的Python绑定库,它允许开发者使用Python语言来创建原生的图形用户界面...

    Python2.5编译器

    Python 2.5 编译器是Python编程语言的一个历史版本,它在2006年发布,提供了许多对Python语言特性和库的改进。在这个版本中,开发者引入了新的功能,增强了性能,并修复了大量的bug。尽管Python 2.5已经不再支持,但...

    python 2.5 学习笔记

    标题“Python 2.5 学习笔记”直接指向我们讨论的核心内容是Python这门编程语言,在这里,我们关注的是Python的2.5版本。由于这个版本发布于2006年,属于较早的版本,但它依然在计算机编程历史上占有重要地位,是很多...

    mysqldb for python2.5 in windows

    windows mysqldb for python2.5 in windows

    python 2.5 for windows and scons 1.2 for windows

    Python 2.5 是 Python 编程语言的一个早期版本,主要针对Windows操作系统进行了优化。它在2006年发布,引入了许多改进和新特性,包括: 1. **增强的性能**:Python 2.5在性能方面有所提升,通过优化内部算法和数据...

    Python 2.5 Reference Card

    ### Python 2.5 Reference Card #### 1. Variable Types ##### 1.1 Numbers - **Integer and Long Integers:** - `42`: A regular integer. - `052`: An octal representation (equivalent to decimal 42). - ...

    Python 2.5 Virtual Machine

    标题“Python 2.5 Virtual Machine”和描述“Python 2.5 Virtual Machine, PPT”表明了我们要讨论的是Python编程语言的版本2.5中的虚拟机机制。在Python的世界中,虚拟机是其执行代码的关键组成部分。虚拟机通常被...

    python2.5中英对照教程

    这个"python2.5中英对照教程"显然是一个非常实用的学习资源,不仅帮助初学者掌握Python 2.5的基本语法和概念,还可以通过中英文对照来提升英语阅读能力。 在Python 2.5中,有几个关键的知识点是值得深入探讨的: 1...

    pywin32.win32(python2.5版本)

    在提供的描述中,“pywin32-217.win32-py2.5.exe”是一个针对Python 2.5版本的特定构建。这意味着它是为运行Python 2.5解释器的系统设计的,可能不兼容更高或更低版本的Python。版本号217表示这是该模块的一个特定...

    windows Python 2.5和3.3.rar

    "windows Python 2.5和3.3.rar" 是一个包含两个不同版本Python的压缩包,分别是Python 2.5和Python 3.3。这两个版本在Python的发展历史上具有重要意义。Python 2.5是2.x系列的一个较旧版本,发布于2006年,而Python ...

    python2.5安装包

    Python 2.5是Python编程语言的一个早期版本,发布于2006年,它包含了许多重要的特性和改进。在本文中,我们将深入探讨Python 2.5的主要特性、安装过程以及与现代Python版本的差异。 **Python 2.5 特性概述** 1. **...

    python2.5配置pylot所需的wxPython numpy matplotlib

    在这个场景中,`python2.5` 配置 `pylot` 库需要依赖于 `wxPython`、`numpy` 和 `matplotlib` 这三个关键组件。下面将详细介绍这三个库以及如何在Python 2.5环境下安装和使用它们。 `wxPython` 是一个用Python语言...

    python 2.5 for windows

    先装python-2.5.1.msi(解释器) 再装pywin32-212.win32-py2.5.exe(编辑器) Windows下Python:http://www.python.org/download/(解释器/平台) http://sourceforge.net/projects/pywin32(编辑器)

    PySVN for python2.5 win32

    在提供的文件名“pywin32-210.win32-py2.5.exe”中,我们可以看出这是pywin32的一个构建,版本号为210,适用于32位Windows系统和Python2.5。通过运行这个安装程序,你可以将缺失的win32com.client模块添加到你的...

    P4python for python2.5

    可用于python2.5的P4python

Global site tag (gtag.js) - Google Analytics