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='\n', 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.
 
                    
                
                
            
        
浙公网安备 33010602011771号