Built-in Functions    
abs() delattr() hash() memoryview() set()
all() dict() help() min() setattr()
any() dir() hex() next() slice()
ascii() divmod() id() object() sorted()
bin() enumerate() input() oct() staticmethod()
bool() eval() int() open() str()
breakpoint() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() __import__()
complex() hasattr() max() round()  
# abs(x)
print(abs(-10)) #
# 取绝对值 ###################################
# all(iterable)
print(all([1,2,3,4,5])) # True
print(all((0,1,2,3,4))) # False
# 可迭代对象中,如果存在一个以上bool为False的,则整体为False ###################################
# any(iterable)
print(any([None,False,(),[],{},])) # False
print(any([None,False,(),[],{},10])) # True
# 可迭代对象中,只要存在一个是True,则为True ###################################
# ascii(object)
print(ascii("abcd")) # 'abcd'
print(ascii("中国")) # '\u4e2d\u56fd' ###################################
# bin(x)
print(bin(3)) # 0b11
print(bin(-10)) # -0b1010
# 二进制 ###################################
# bool([x])
print(bool(None)) # False
print(bool(2)) # True ###################################
# breakpoint(*args, **kws)
# print(breakpoint()) # 3.6 ###################################
# bytearray([source[, encoding[, errors]]])
print(bytearray()) # bytearray(b'')
print(bytearray([1,2,3])) # bytearray(b'\x01\x02\x03')
print(bytearray('test', 'utf-8')) # bytearray(b'test')
# 如果 source 为整数,则返回一个长度为 source 的初始化数组;
# 如果 source 为字符串,则按照指定的 encoding 将字符串转换为字节序列;
# 如果 source 为可迭代类型,则元素必须为[0 ,255] 中的整数;
# 如果 source 为与 buffer 接口一致的对象,则此对象也可以被用于初始化 bytearray。
# 如果没有输入任何参数,默认就是初始化数组为0个元素。
# bytearray() 方法返回一个新字节数组。这个数组里的元素是可变的,并且每个元素的值范围: 0 <= x < 256。 ###################################
# bytes([source[, encoding[, errors]]])
print(bytes("中国","utf-8")) # b'\xe4\xb8\xad\xe5\x9b\xbd'
print(bytes("中国","gbk")) # b'\xd6\xd0\xb9\xfa'
print(bytes("hello world","utf-8")) # b'hello world'
print(bytes("hello world","gbk")) # b'hello world' ###################################
# callable(object)
def test():
pass class T():
pass
class T1():
def __call__(self):
pass print(callable([1,2,3])) # False
print(callable(test)) # True
print(callable(T())) # False
print(callable(T1())) # True
# 验证对象是否实现了__call__方法 ###################################
# chr(i)
print(chr(77)) # M
# 通过ascii码得出对应的字符
print(ord("M")) #
# 反向,查找出字符对应的ascii码 ###################################
# classmethod
# 类方法 ###################################
# compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
str = "for i in range(0,10): print(i)"
c = compile(str,'','exec') # 编译为字节代码对象
exec(c)
#
#
#
#
#
#
#
#
#
#
# compile() 函数将一个字符串编译为字节代码。 ###################################
# complex([real[, imag]])
print(complex(1, 2)) # (1+2j)
# complex() 函数用于创建一个值为 real + imag * j 的复数或者转化一个字符串或数为复数。如果第一个参数为字符串,则不需要指定第二个参数。 ###################################
# delattr(object, name)
# 反射 ###################################
# dir([object])
# 查看对象的namespace ###################################
# divmod(a, b)
print(divmod(100,3)) # (33, 1)
# a被除数,b除数
# res:(商,余数) ###################################
# enumerate(iterable, start=0)
for index,value in enumerate([123,32,2],start=3):
print(index,value)
# 3 123
# 4 32
# 5 2 ###################################
# eval(expression, globals=None, locals=None)
print(eval("1+2+3*4")) #
print(eval("x+y",{"x":1,"y":2})) #
# 计算指定表达式的值 ###################################
# exec(object[, globals[, locals]])
class T():
pass
exec("x = T()")
print(x) # <__main__.T object at 0x05A81050> x = 10
expr = """
z = 30
sum = x + y + z #一大包代码
print(sum)
"""
def func():
y = 20
exec(expr) # 10+20+30
exec(expr,{'x':1,'y':2}) # 30+1+2
exec(expr,{'x':1,'y':2},{'y':3,'z':4}) # 30+1+3,x是定义全局变量1,y是局部变量
func()
#
#
# # 动态执行python代码,exec无返回值 ###################################
# filter(function,iterable)
print(list(filter(lambda x:x>4,[1,2,3,4,5,6,7,8,9]))) # [5, 6, 7, 8, 9]
# filter对象是一个迭代器,筛选 ###################################
# float([x])
print(float(-123)) # -123.0
print(float('1e-003')) # 0.001
print(float('+1E6')) # 1000000.0
print(float("-Infinity")) # -inf ###################################
# format(value[, format_spec])
print(format(3,'b')) #转换成二进制 '11'
print(format(314159267,'0.2E')) #科学计数法,指定保留2位小数,采用大写E表示 '3.14E+08' ###################################
# frozenset([iterable])
print(frozenset([1,2,3,4])) # frozenset({1, 2, 3, 4})
# 不能改变,没有add,remove ###################################
# getattr(object, name[, default])
# 反射 ###################################
# globals()
print(globals())
# {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x03B6B450>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'D:/Python相关/过程project/爬虫复习/第一次review/tmp.py', '__cached__': None, 'test': <function test at 0x057F07C8>, 'T': <class '__main__.T'>, 'T1': <class '__main__.T1'>, 'index': 5, 'value': 2, 'x': 10, 'expr': '\nz = 30\nsum = x + y + z #一大包代码\nprint(sum)\n', 'func': <function func at 0x057F0780>}
# 全局变量 ###################################
# hasattr(object, name)
# 反射 ###################################
# hash(object)
print(hash('good good study')) # -724571439
print(hash(1.0)) #
print(hash(1)) #
print(hash(1.0000)) #
# hash() 用于获取取一个对象(字符串或者数值等)的哈希值。 ###################################
# help([object])
help('str')
# help() 函数用于查看函数或模块用途的详细说明。 ###################################
# hex(x)
print(hex(255)) # 0xff
print(hex(12)) # 0xc
print(type(hex(123))) # <class 'str'>
# hex() 函数用于将10进制整数转换成16进制,以字符串形式表示。 ###################################
# id([object])
# id() 函数用于获取对象的内存地址。 ###################################
# input([prompt])
# input("input:") # input:
# input() 函数接受一个标准输入数据,返回为 string 类型。 ###################################
# class int(x, base=10)
print(int(3.2)) #
print(int('',16)) #
print(int("",8)) #
# int() 函数用于将一个字符串或数字转换为整型。 ###################################
# isinstance(object, classinfo)
# isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type()。 ###################################
# issubclass(class, classinfo)
# issubclass() 方法用于判断参数 class 是否是类型参数 classinfo 的子类。 ###################################
# iter(object[, sentinel])
l = iter([1,2,3])
print(next(l)) #
print(next(l)) #
# iter() 函数用来生成迭代器。 ###################################
# len( s )
# Python len() 方法返回对象(字符、列表、元组等)长度或项目个数。 ###################################
# list( seq )
# list() 方法用于将元组转换为列表。 ###################################
# locals()
# locals() 函数会以字典类型返回当前位置的全部局部变量。 ###################################
# map(function, iterable, ...)
print(list(map(lambda x:x**3,[1,2,3]))) # [1, 8, 27]
# map() 会根据提供的函数对指定序列做映射。 ###################################
# max(iterable, *[, key, default])
# max(arg1, arg2, *args[, key])
d = {"a":10,"b":9,"c":8,"d":7,"e":6}
print(max(d)) # e
print(max(d,key=lambda x:d[x])) # a ###################################
# memoryview(obj)
v = memoryview(bytearray("abcefg", 'utf-8'))
print(v[1]) #
print(v[-1]) #
print(v[1:4]) # <memory at 0x09F7D8B8>
print(v[1:4].tobytes()) # b'bce'
# memoryview() 函数返回给定参数的内存查看对象(Momory view)。
# 所谓内存查看对象,是指对支持缓冲区协议的数据进行包装,在不需要复制对象基础上允许Python代码访问。 ###################################
# min(iterable, *[, key, default])
# min(arg1, arg2, *args[, key])
d = {"a":10,"b":9,"c":8,"d":7,"e":6}
print(min(d)) # a
print(min(d,key=lambda x:d[x])) # e ###################################
# next(iterator[, default])
# next() 返回迭代器的下一个项目。 ###################################
# oct(x)
print(oct(10)) # 0o12
print(oct(20)) # 0o24
# oct() 函数将一个整数转换成8进制字符串。 ###################################
# open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) ###################################
# ord(c)
# ord() 函数是 chr() 函数(对于8位的ASCII字符串)或 unichr() 函数(对于Unicode对象)的配对函数,它以一个字符(长度为1的字符串)作为参数,返回对应的 ASCII 数值,或者 Unicode 数值,如果所给的 Unicode 字符超出了你的 Python 定义范围,则会引发一个 TypeError 的异常。 ###################################
# pow(x, y[, z])
print(pow(2,10)) #
print(pow(2,10,10)) # 4,取模,等价于pow(x,y) %z
# 返回 xy(x的y次方) 的值。 ###################################
# print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) ###################################
# property(fget=None, fset=None, fdel=None, doc=None) ###################################
# range(stop)
# range(start, stop[, step]) ###################################
# repr(object)
# repr() 函数将对象转化为供解释器读取的形式。 ###################################
# reversed(seq)
seqRange = range(5, 9)
print(list(reversed(seqRange))) # [8, 7, 6, 5]
# reversed 函数返回一个反转的迭代器。 ###################################
# round(number[, ndigits])
print ("round(70.23456) : ", round(70.23456)) # round(70.23456) : 70
print ("round(-100.000056, 3) : ", round(-100.000056, 3)) # round(-100.000056, 3) : -100.0
# round() 方法返回浮点数x的四舍五入值。 ###################################
# set([iterable]) ###################################
# setattr(object, name, value)
# 反射 ###################################
# slice(stop)
# slice(start, stop[, step])
myslice = slice(5) # 设置截取5个元素的切片
myslice1 = slice(2,9)
myslice2 = slice(2,9,3)
arr = range(10)
print(arr[myslice]) # range(0, 5)
print(arr[myslice1]) # range(2, 9)
print(arr[myslice2]) # range(2, 9, 3)
# slice() 函数实现切片对象,主要用在切片操作函数里的参数传递。 ###################################
# sorted(iterable, *, key=None, reverse=False)
print(sorted([5, 2, 3, 1, 4])) # [1, 2, 3, 4, 5]
print(sorted([5, 0, 6, 1, 2, 7, 3, 4], key=lambda x: x*-1)) # [7, 6, 5, 4, 3, 2, 1, 0]
# sorted() 函数对所有可迭代的对象进行排序操作。 ###################################
# staticmethod ###################################
# str(object='')
# str(object=b'', encoding='utf-8', errors='strict') ###################################
# sum(iterable[, start])
print(sum((2, 3, 4), 1)) # 10 元组计算总和后再加 1
print(sum((range(3,5)), 3)) # 10 元组计算总和后再加 3
# sum() 方法对系列进行求和计算。 ###################################
# super([type[, object-or-type]])
# super() 函数是用于调用父类(超类)的一个方法。 ###################################
# tuple([iterable])
# tuple 函数将列表转换为元组。。 ###################################
# type(object)
# type(name, bases, dict)
print(type(1)) # <class 'int'>
print(type("abc")) # <class 'str'>
# 三个参数
class X():
a = 1
z = type("X",(object,),dict(a=1))
print(z) # <class '__main__.X'> ###################################
# vars([object])
class X(object):
a = 1
print(vars(X)) # {'__module__': '__main__', 'a': 1, '__dict__': <attribute '__dict__' of 'X' objects>, '__weakref__': <attribute '__weakref__' of 'X' objects>, '__doc__': None}
# vars() 函数返回对象object的属性和属性值的字典对象。 ###################################
# zip(*iterables)
a = [1,2,3]
b = [4,5,6]
c = [7,8,9]
print(list(zip(a,b,c))) # [(1, 4, 7), (2, 5, 8), (3, 6, 9)] ###################################
# __import__(name, globals=None, locals=None, fromlist=(), level=0)
# __import__() 函数用于动态加载类和函数 。

逐个实现

参考or转发

 http://www.runoob.com/python/python-built-in-functions.html

Python基础_内置函数的更多相关文章

  1. 十六. Python基础(16)--内置函数-2

    十六. Python基础(16)--内置函数-2 1 ● 内置函数format() Convert a value to a "formatted" representation. ...

  2. 十五. Python基础(15)--内置函数-1

    十五. Python基础(15)--内置函数-1 1 ● eval(), exec(), compile() 执行字符串数据类型的python代码 检测#import os 'import' in c ...

  3. python基础(15):内置函数(一)

    1. 内置函数 什么是内置函数? 就是python给你提供的,拿来直接⽤的函数,比如print,input等等,截⽌到python版本3.6.2 python⼀共提供了68个内置函数.他们就是pyth ...

  4. python基础(内置函数+文件操作+lambda)

    一.内置函数 注:查看详细猛击这里 常用内置函数代码说明: # abs绝对值 # i = abs(-123) # print(i) #返回123,绝对值 # #all,循环参数,如果每个元素为真,那么 ...

  5. Python基础:内置函数

    本文基于Python 3.6.5的标准库文档编写,罗列了英文文档中介绍的所有内建函数,并对其用法进行了简要介绍. 下图来自Python官网:展示了所有的内置函数,共计68个(14*4+12),大家可以 ...

  6. 第六篇:python基础_6 内置函数与常用模块(一)

    本篇内容 内置函数 匿名函数 re模块 time模块 random模块 os模块 sys模块 json与pickle模块 shelve模块 一. 内置函数 1.定义 内置函数又被称为工厂函数. 2.常 ...

  7. Python基础编程 内置函数

    内置函数 内置函数(一定记住并且精通) print()屏幕输出 int():pass str():pass bool():pass set(): pass list() 将一个可迭代对象转换成列表 t ...

  8. python基础(16):内置函数(二)

    1. lamda匿名函数 为了解决⼀些简单的需求⽽设计的⼀句话函数 # 计算n的n次⽅ def func(n): return n**n print(func(10)) f = lambda n: n ...

  9. 学习PYTHON之路, DAY 4 - PYTHON 基础 4 (内置函数)

    注:查看详细请看https://docs.python.org/3/library/functions.html#next 一 all(), any() False: 0, Noe, '', [], ...

随机推荐

  1. tomcat服务器宕机解决方案

    报错信息: java.lang.Object.wait(Native Method) java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:1 ...

  2. HDU 2639(01背包求第K大值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2639 Bone Collector II Time Limit: 5000/2000 MS (Jav ...

  3. SEGGER RTT STOP/SLEEP 模式下使用

    1.问题详述, M3/M4内核在sleep 或者 STOP模式 下,内核是不工作的,因此需要 以下 几步操作 第一步: 开启 低功耗模式下,debug 的连接 DBGMCU_Config(DBGMCU ...

  4. IOPS、带宽(band width)、吞吐量 (throughput)

    SAN和NAS存储一般都具备2个评价指标:IOPS和带宽(throughput),两个指标互相独立又相互关联.体现存储系统性能的最主要指标是IOPS.   IOPS (Input/Output Per ...

  5. SQL基础语法的单表操作 select|insert|update|delete(增删改查) 简单使用

    以下案列以此表举例 1.select(查询) select简单的查询分为两种 注:字段也就是表结构中的列的名称 第一种: select  字段名  from  表名 此种查询只列出你所需要查询的字段, ...

  6. 如何保障Go语言基础代码质量?

    为什么要谈这个topic? 实践中,质量保障体系的建设,主要针对两个目标: 一是不断提高目标业务测试覆盖率,保障面向客户的产品质量:二就是尽可能的提高人效,增强迭代效率.而构建全链路质量卡点就是整个体 ...

  7. 2017-2018-2 《网络对抗技术》20155322 Exp6 信息搜集与漏洞扫描

    [-= 博客目录 =-] 1-实践目标 1.1-实践介绍 1.2-实践内容 1.3-实践要求 2-实践过程 2.1-Google hacking & ZoomEye 2.2-DNS.IP信息收 ...

  8. mfc 类

    知识点 类的概念 类的相关术语 定义类 使用类 一.类的概念 简单的说类就是数据与函数综合体,它是用户自定义类型. 二.类的相关术语 类的实例称为对象. 类在定义中隐式地包含数据和操作函数,这种思想称 ...

  9. 21-[模块]-configparser

    1.configparser模块 此模块用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. 来看一个好多软件的常见配置文件格式如下 [DEFA ...

  10. 【LNOI2014】LCA

    题面 题解 考察\(dep[\mathrm{LCA}(i, x)]\)的性质,发现它是\(i\)和\(x\)的链交的长度. 那么对每个\(i\)所在的链打一个区间加标记,询问时算一下\(x\)所在的链 ...