zoukankan      html  css  js  c++  java
  • python(一)内置函数和变量

    内置函数

    python的内置函数可以直接使用,无需import

    函数主要分为以下几大类:

    1. 计算

    • abs() 求绝对值
    • hash() 求哈希值
    • bin(x) 求二进制数字
    • divmod(a, b) 求商和余数
    • pow(x, y[, z]) 求n次方
    • round(number[, ndigits]) 控制精度

    2. 循环、迭代、排序

    • all()/any()/filter(function, iterable)/itertools.filterfalse() 判断、正/反过滤
    • map(function, iterable, ...) 转化
    • enumerate(iterable, start=0) 带序号的迭代
    • zip(*iterables)/itertools.zip_longest() 多个迭代
    • iter(object[, sentinel])/next(iterator[, default]) 生成迭代器
    • reversed(seq) 生成逆序迭代器
    • max(iterable, *[, key, default])/max(arg1, arg2, *args[, key])/min(iterable, *[, key, default])/min(arg1, arg2, *args[, key]) 求最大/最小值
    • class range(stop)/class range(start, stop[, step])
    • sorted(iterable, *, key=None, reverse=False)/functools.cmp_to_key() 带有key的排序(不建议使用只能用于list的原地排序方法sort()
    • sum(iterable[, start]) 求和

    3. 类和对象、系统

    • callable(object)
    • repr(object)
    • dir()
    • id(object)
    • input([prompt])
    • issubclass(class, classinfo)
    • len(s)
    • isinstance(object, classinfo)/class type(object)/class type(name, bases, dict) 建议使用type()isinstance允许子类实例属于父类
    • open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
    • print(*objects, sep=' ', end=' ', file=sys.stdout, flush=False)

    4. 字符串

    • class float([x])
    • eval(expression[, globals[, locals]])
    • chr(i)/ord(c)

    5. TBD

    TBD:

    • ascii(object)
    • breakpoint(*args, **kws)
    • class bytearray([source[, encoding[, errors]]])
    • class bytes([source[, encoding[, errors]]])
    • compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
    • class complex([real[, imag]])
    • delattr(object, name)/getattr(object, name[, default])/hasattr(object, name)/setattr(object, name, value)
    • class dict(**kwarg)
    • exec(object[, globals[, locals]])
    • format(value[, format_spec])
    • class frozenset([iterable])
    • globals()/locals()
    • help([object])
    • hex(x)
    • class memoryview(obj)
    • oct(x)
    • class property(fget=None, fset=None, fdel=None, doc=None)
    • class slice(stop)/class slice(start, stop[, step])
    • @staticmethod
    • class str(object='')/class str(object=b'', encoding='utf-8', errors='strict')
    • super([type[, object-or-type]])
    • vars([object])

    内置变量

    • False
    • True
    • None
    • NotImplemented
    • Ellipsis: The same as the ellipsis literal “...”. Special value used mostly in conjunction with extended slicing syntax for user-defined container data types.
    • debug: This constant is true if Python was not started with an -O option. See also the assert statement.
  • 相关阅读:
    二维数组实现01背包
    一维数组实现01背包
    js实现最长子串算法
    mysql__存储过程
    mysql 分页查询 limit
    转:严重: Exception loading sessions from persistent storage
    struts2---ValueStack对象
    struts2----ognl
    什么是JavaBean?
    EL表达式
  • 原文地址:https://www.cnblogs.com/YoungF/p/14395287.html
Copyright © 2011-2022 走看看