python内置方法、模块讲解(二十一)

  • 2016-05-20 22:58:23
  • 1138
  • 0

五十七、open方法

​1、定义:

open(...)
    open(name[, mode[, buffering]]) -> file object

    Open a file using the file() type, returns a file object.  This is the
    preferred way to open a file.  See file.__doc__ for further information.

​2、解释:用file函数类型打开一个文件并返回一个文件对象。这个方法是打开一个文件的首先方法。

​3、举例:(略)

​五十八、ord方法

​1、定义:

ord(...)
    ord(c) -> integer

    Return the integer ordinal of a one-character string.

​2、解释:返回一个单字符串的整数序号(即ascii码)

​3、举例:

>>> ord('a')
97
>>> ord('A')
65
>>> ord('(')
40

五十九、pow方法

1、定义:

pow(...)
    pow(x, y[, z]) -> number

    With two arguments, equivalent to x**y.  With three arguments,
    equivalent to (x**y) % z, but may be more efficient (e.g. for longs).

2、解释:若只传入两个参数(即x、y)即相当于x**y,若传入三个参数(即x、y、z)即相当于(x**y)%z,但效率要比它们更高(如对长整型)。

3、举例:

>>> pow(4,2)
16
>>> 4**2
16
>>> pow(4,2,10)
6
>>> 4**2%10
6
 

 


发表评论

* *