Python内置函数 | V3.9.1 | 共计155个

还没学完, 还没记录完, 不知道自己能不能坚持记录下去


1.ArithmeticError 2.AssertionError 3.AttributeError 4.BaseException 5.BlockingIOError
6.BrokenPipeError 7.BufferError 8.BytesWarning 9.ChildProcessError 10.ConnectionAbortedError
11.ConnectionError 12.ConnectionRefusedError 13.ConnectionResetError 14.DeprecationWarning 15.EOFError
16.Ellipsis 17.EnvironmentError 18.Exception 19.False 20.FileExistsError
21.FileNotFoundError 22.FloatingPointError 23.FutureWarning 24.GeneratorExit 25.IOError
26.ImportError 27.ImportWarning 28.IndentationError 29.IndexError 30.InterruptedError
31.IsADirectoryError 32.KeyError 33.KeyboardInterrupt 34.LookupError 35.MemoryError
36.ModuleNotFoundError 37.NameError 38.None 39.NotADirectoryError 40.NotImplemented
41.NotImplementedError 42.OSError 43.OverflowError 44.PendingDeprecationWarning 45.PermissionError
46.ProcessLookupError 47.RecursionError 48.ReferenceError 49.ResourceWarning 50.RuntimeError
51.RuntimeWarning 52.StopAsyncIteration 53.StopIteration 54.SyntaxError 55.SyntaxWarning
56.SystemError 57.SystemExit 58.TabError 59.TimeoutError 60.True
61.TypeError 62.UnboundLocalError 63.UnicodeDecodeError 64.UnicodeEncodeError 65.UnicodeError
66.UnicodeTranslateError 67.UnicodeWarning 68.UserWarning 69.ValueError 70.Warning
71.WindowsError 72.ZeroDivisionError 73.__build_class__ 74.__debug__ 75.__doc__
76.__import__ 77.__loader__ 78.__name__ 79.__package__ 80.__spec__
81.abs 82.all 83.any 84.ascii 85.bin
86.bool 87.breakpoint 88.bytearray 89.bytes 90.callable
91.chr 92.classmethod 93.compile 94.complex 95.copyright
96.credits 97.delattr 98.dict 99.dir 100.divmod
101.enumerate 102.eval 103.exec 104.execfile 105.exit
106.filter 107.float 108.format 109.frozenset 110.getattr
111.globals 112.hasattr 113.hash 114help 115.hex
116.id 117.input 118.int 119.isinstance 120.issubclass
121.iter 122.len 123.license 124.list 125.locals
126.map 127.max 128.memoryview 129.min 130.next
131.object 132.oct 133.open 134.ord 135.pow
136.print 137.property 138.quit 139.range 140.repr
141.reversed 142.round 143.runfile 144.set 145.setattr
146.slice 147.sorted 148.staticmethod 149.str 150.sum
151.super 152.tuple 153.type 154.vars 155.zip

1.ArithmeticError

2.AssertionError

3.AttributeError

4.BaseException

5.BlockingIOError

6.BrokenPipeError

7.BufferError

8.BytesWarning

9.ChildProcessError

10.ConnectionAbortedError

11.ConnectionError

12.ConnectionRefusedError

13.ConnectionResetError

14.DeprecationWarning

15.EOFError

16.Ellipsis

17.EnvironmentError

18.Exception

19.False

20.FileExistsError

21.FileNotFoundError

22.FloatingPointError

23.FutureWarning

24.GeneratorExit

25.IOError

26.ImportError

27.ImportWarning

28.IndentationError

29.IndexError

30.InterruptedError

31.IsADirectoryError

32.KeyError

33.KeyboardInterrupt

34.LookupError

35.MemoryError

36.ModuleNotFoundError

37.NameError

38.None

39.NotADirectoryError

40.NotImplemented

41.NotImplementedError

42.OSError

43.OverflowError

44.PendingDeprecationWarning

45.PermissionError

46.ProcessLookupError

47.RecursionError

48.ReferenceError

49.ResourceWarning

50.RuntimeError

51.RuntimeWarning

52.StopAsyncIteration

53.StopIteration

54.SyntaxError

55.SyntaxWarning

56.SystemError

57.SystemExit

58.TabError

59.TimeoutError

60.True

61.TypeError

62.UnboundLocalError

63.UnicodeDecodeError

64.UnicodeEncodeError

65.UnicodeError

66.UnicodeTranslateError

67.UnicodeWarning

68.UserWarning

69.ValueError

70.Warning

71.WindowsError

72.ZeroDivisionError

73.__build_class__

74.__debug__

75.__doc__

76.__import__

77.__loader__

78.__name__

79.__package__

80.__spec__

81.abs

82.all

83.any

84.ascii

85.bin

86.bool

87.breakpoint

88.bytearray

89.bytes

90.callable

91.chr

92.classmethod

修饰符:类方法 @classmethod | 无需显式地传递类名做实参

  1. class Computer:
  2. # 类属性modules
  3. __modules = {"cpu":"Intel", "内存":"镁光", "硬盘":"970-Pro"}
  4. # 设定修饰符@类方法 | 类的函数或者叫类的方法output_modules
  5. @classmethod
  6. def output_modules(cls):
  7. for (i,s) in cls.__modules.items():
  8. print(i, ':', s)
  9. # 调用类的方法output_modules,无需显式地传递类名做实参
  10. Computer.output_modules()
  11. #-------------------------------------------------------------
  12. # 输出结果:
  13. # cpu : Intel
  14. # 内存 : 镁光
  15. # 硬盘 : 970-Pro

也可被其他类直接进行调用(感觉有点全局的意思), 看例子代码如下:

  1. class Computer:
  2. # 类属性modules
  3. __modules = {"cpu":"Intel", "内存":"镁光", "硬盘":"970-Pro"}
  4. # 设定修饰符@类方法 | 类的函数或者叫类的方法output_modules
  5. @classmethod
  6. def output_modules(cls):
  7. for (i,s) in cls.__modules.items():
  8. print(i, ':', s)
  9. class OtherClass:
  10. def __init__(self):
  11. pass
  12. def _test_OtherClass(self):
  13. # 调用类的方法output_modules,无需显式地传递类名做实参
  14. Computer.output_modules()
  15. aaaa = OtherClass()
  16. aaaa._test_OtherClass()
  17. #-------------------------------------------------------------
  18. # 输出结果:
  19. # cpu : Intel
  20. # 内存 : 镁光
  21. # 硬盘 : 970-Pro

93.compile

94.complex

95.copyright

96.credits

97.delattr

98.dict

99.dir

100.divmod

101.enumerate

102.eval

103.exec

104.execfile

105.exit

106.filter

107.float

108.format

109.frozenset

110.getattr

111.globals

112.hasattr

113.hash

114help

115.hex

116.id

117.input

118.int

119.isinstance

120.issubclass

121.iter

122.len

123.license

124.list

125.locals

126.map

127.max

128.memoryview

129.min

130.next

131.object

132.oct

133.open

134.ord

135.pow

136.print

137.property

此修饰符可赋值给变量, 语法为:x = property(getx, setx, delx)

  • 如果是以此种方法的话, 函数名或者说是方法名可以不相同

如果是以装饰器形式使用的话, 函数名或者说是方法名必须相同, 例子代码如下:

  1. class Computer:
  2. # 类属性 __modules
  3. __modules = {"cpu":"Intel", "内存":"镁光", "硬盘":"970-Pro"}
  4. def __init__(self):
  5. pass
  6. # 获取字典的key
  7. @property
  8. def modules_property(self):
  9. # 字典 __modules的key 取出来变成列表
  10. __loops = [i for i in self.__modules]
  11. for ii in range(len(self.__modules)):
  12. print(__loops[ii], ':', self.__modules[__loops[ii]])
  13. # 给字典新增数据
  14. @modules_property.setter
  15. def modules_property(self, key_value):
  16. self.__modules[key_value[0]] = key_value[1]
  17. # 删除字典中内容, 这里没办法通过@modules_property.deleter以达到删除字典中某个键值
  18. # 所以换成了 静态方法 来删除键值
  19. @staticmethod
  20. def del_modules_property(__del, key):
  21. try:
  22. # dels.__modules.pop(key, 'Error, 删除的内容不存在!')
  23. __del.__modules.pop(key)
  24. except KeyError:
  25. print(f'Error, 删除的键: {key} 不存在!')# 这个引用变量 应该在v3.6版本以下不兼容...
  26. # print('Error, 删除的键: {keys} 不存在!'.format(keys=key))
  27. # 实例化类
  28. aaaa = Computer()
  29. print('打印原有字典内容')
  30. aaaa.modules_property
  31. print('----------分隔符-----------')
  32. print('打印新增后字典内容')
  33. # 通过@modules_property.setter, 给字典新增数据
  34. aaaa.modules_property = ('机箱', '海盗船')
  35. # 通过@property,其实也是@getattr, 取出字典中的键值内容
  36. aaaa.modules_property
  37. print('----------分隔符-----------')
  38. print('打印删除后字典内容')
  39. # 通过静态方法@staticmethod, 删除字典中某个元素,或者说成删除字典中某个键值内容
  40. Computer.del_modules_property(Computer, 'cpu')
  41. # 通过@property, 再次打印字典内容,看下是否正常删除了
  42. aaaa.modules_property
  43. # -------------------------------------------------------------
  44. # 打印原有字典内容
  45. # cpu : Intel
  46. # 内存 : 镁光
  47. # 硬盘 : 970-Pro
  48. # ----------分隔符-----------
  49. # 打印新增后字典内容
  50. # cpu : Intel
  51. # 内存 : 镁光
  52. # 硬盘 : 970-Pro
  53. # 机箱 : 海盗船
  54. # ----------分隔符-----------
  55. # 打印删除后字典内容
  56. # 内存 : 镁光
  57. # 硬盘 : 970-Pro
  58. # 机箱 : 海盗船

138.quit

139.range

140.repr

141.reversed

142.round

143.runfile

144.set

145.setattr

146.slice

147.sorted

148.staticmethod

# 修饰符:静态方法 @staticmethod | 必须显式地传递类名做实参

  1. class Computer:
  2. # 类属性modules
  3. __modules = {"cpu":"Intel", "内存":"镁光", "硬盘":"970-Pro"}
  4. # 在静态方法search_module中定义形参var,准备传递类:Computer
  5. # 调用时必须显性地传递类名,才能实现类方法一样的效果
  6. # 设定修饰符@静态方法 | 类的函数或者叫类的方法search_module
  7. @staticmethod
  8. def search_module(var, module_value):
  9. print(var.__modules[module_value])
  10. Computer.search_module(Computer, "cpu")
  11. Computer.search_module(Computer, "内存")
  12. Computer.search_module(Computer, "硬盘")
  13. #-------------------------------------------------------------
  14. # 输出结果:
  15. # Intel
  16. # 镁光
  17. # 970-Pro

也可被其他类直接进行调用(有点全局的意思.....), 看例子代码如下:

  1. class Computer:
  2. # 类属性modules
  3. __modules = {"cpu":"Intel", "内存":"镁光", "硬盘":"970-Pro"}
  4. # 在静态方法search_module中定义形参var,准备传递类:Computer
  5. # 调用时必须显性地传递类名,才能实现类方法一样的效果
  6. # 设定修饰符@静态方法 | 类的函数或者叫类的方法search_module
  7. @staticmethod
  8. def search_module(var, module_value):
  9. print(var.__modules[module_value])
  10. class OtherClass:
  11. def __init__(self):
  12. pass
  13. def _test_OtherClass(self):
  14. # 调用类的静态方法search_module,必须显式地传递类名做实参
  15. Computer.search_module(Computer, "cpu")
  16. Computer.search_module(Computer, "内存")
  17. Computer.search_module(Computer, "硬盘")
  18. aaaa = OtherClass()
  19. aaaa._test_OtherClass()
  20. #-------------------------------------------------------------
  21. # 输出结果:
  22. # Intel
  23. # 镁光
  24. # 970-Pro

149.str

150.sum

151.super

super函数不需要明确的给出任何 "被调用类" 的名称, 学习中觉得 子类-父类-超类 叫起来很绕, 就自认为叫成 "被调用类" 方便自己理解

  • 假设定义了三个类: A B C
  • 类A 继承 类B, 类A 是 类B 的子类 | 类B 是 类A 的父类(被调用类)
  • 类B 继承 类C, 类B 是 类C 的子类 | 类C 是 类B 的父类(被调用类)
  • 类A 间接继承 类C , 类C 是 类A 的超类(被调用类)
  • 例子待定

152.tuple

153.type

154.vars

155.zip

Python | 内置函数(BIF)的更多相关文章

  1. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

  2. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  3. Python基础篇【第2篇】: Python内置函数(一)

    Python内置函数 lambda lambda表达式相当于函数体为单个return语句的普通函数的匿名函数.请注意,lambda语法并没有使用return关键字.开发者可以在任何可以使用函数引用的位 ...

  4. [python基础知识]python内置函数map/reduce/filter

    python内置函数map/reduce/filter 这三个函数用的顺手了,很cool. filter()函数:filter函数相当于过滤,调用一个bool_func(只返回bool类型数据的方法) ...

  5. Python内置函数进制转换的用法

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...

  6. Python内置函数(12)——str

    英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string  ...

  7. Python内置函数(61)——str

    英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string ...

  8. 那些年,很多人没看懂的Python内置函数

    Python之所以特别的简单就是因为有很多的内置函数是在你的程序"运行之前"就已经帮你运行好了,所以,可以用这个的特性简化很多的步骤.这也是让Python语言变得特别的简单的原因之 ...

  9. Python 内置函数笔记

    其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...

随机推荐

  1. Linux如何查看某个端口是否被占用

    1.netstat  -anp  |grep   端口号 2.netstat   -nultp(此处不用加端口号) 3.netstat  -anp  |grep  82    查看82端口的使用情况

  2. jdk_8接口的内部内容

    目标: 如何创建已定义好的接口类型的对象呢? 步骤: 实现的概述 抽象方法的使用 默认方法的使用 静态方法的使用 接口的常量使用 讲解: 实现的概述 类与接口的关系为实现关系,即类实现接口,该类可以称 ...

  3. c++思维导图

    转自:https://blog.csdn.net/qq_37941471/article/details/84026920

  4. Python 与 C++ 向量

    Python 与 C++ 向量 Python 和 C++ 对比 我们再回到向量!你已经学习了如何声明一个空的向量. 在下面的代码中,你可以比较 Python 列表和 C++ 向量的语法.你会看到,C+ ...

  5. 小程序输入框闪烁BUG解决方案

    前言 本人所说的小程序,都是基于mpvue框架而上的,因此BUG可能是原生小程序的,也有可能是mpvue的. 问题描述 在小程序input组件中,如果使用v-model进行双向绑定,在输入时会出现光标 ...

  6. 将java的对象或集合转成json形式字符串

    将java的对象或集合转成json形式字符串: json的转换插件是通过java的一些工具,直接将java对象或集合转换成json字符串. 常用的json转换工具有如下几种: 1)jsonlib 需要 ...

  7. [ Linux ] 设置服务器开机自启端口

    https://www.cnblogs.com/yeungchie/ 需要用到的工具: crontab iptables crontab.set SHELL=/bin/bash PATH=/sbin: ...

  8. python---二维数组的查找

    """ 在一个二维数组中(每个一维数组的长度相同), 每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序. """ # ...

  9. python---双链表的常用操作

    class Node(object): """结点""" def __init__(self, data): self.data = dat ...

  10. ArrayList扩容问题

    今天上午上课在看JavaSE的面经,其中有问关于ArrayList和LinkedList的区别,就突然思考到,既然ArrayList是采用数组形式存储数据,对比我们自己使用到的数组,为什么ArrayL ...