zoukankan      html  css  js  c++  java
  • Python学习足迹(3)

    1,一些内置函数:
    coerce 把 两个变元变成同一种类型。
    >>> coerce(1,2.2)
    (1.0, 2.2000000000000002)

    filter, filter(function, list) (2)里面已经说了。

    input()输入一个数字
    >>> a=input("age: ")
    age: 20
    >>> a
    20

    open(),打开文件,open(filename,mode)
    pow(x,y), pow(2,10) = 1024
    raw_input( prompt ) 输入字符串
    reduce(fun,list)
    >>> import operator
    >>> reduce(operator.add,[1,23])
    24

    range,xrange, xrange不会引起内存不足。
    len()返回长度
    max(1,2,3) = 3
    min(1,2,3) =1
    setattr(object, name, value)
    getattr(object,name)
    hasattr(object,name)
    delattr(object,name)
    type(object), type( '' ) = <type 'str'>
    dir()列出可用的语法,比如: import os : dir(os)
    callable(object),是否可以调用

    abs()
    cmp(x,y) , x > y 返回 1, x=y 返回 0, x<y, 返回 -1
    round(num, dec),  round(10.45,1 ) = 10.5, dec是保留的小数的位数。
    eval( '2*3+ 1' ) = 7
    exec,执行python语句,
    >>> a='print "hello"'
    >>> exec a
    hello
    execfile(file),执行file里面的python

    chr(integer), chr(65)='A',
    ord('A') = 65
    hex(),转换为16进制。 hex(12) = 0xc

    2,文件操作
    read(), read(nbytes),如果带有数字,那么读出nbytes个字节,否则全部读出。
    readline()读出一行
    readlines()读出所有的行,作为list返回。
    write(),写入字符串。
    writelines(list),写入多行
    seek()转向文件的位置,0表示开头,1表示当前,2表示尾部。
    tell(),返回当前指针。
    flush()
    close()

  • 相关阅读:
    flex布局
    input框不能输入问题
    JS的innerHTML完成注册表
    CSS的z-index属性和box-shadow属性
    JS个人笔记
    css照片墙
    透明度设置
    a标签的name属性
    iframe标签
    title属性
  • 原文地址:https://www.cnblogs.com/Hacker/p/31390.html
Copyright © 2011-2022 走看看