Categories: Python教程

Python3 内置函数

本节介绍了 Python3 中的内置函数以及调试的两种方法。

abs()dict()help()min()setattr()
all()dir()hex()next()slice()
any()divmod()id()object()sorted()
ascii()enumerate()input()oct()staticmethod()
bin()eval()int()open()str()
bool()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()
delattr()hash()memoryview()set()

Python 调试方法

1、print

print('here')
# 可以发现某段逻辑是否执行
# 打印出变量的内容

2、assert

assert false, 'blabla'
# 如果条件不成立,则打印出 'blabla' 并抛出AssertionError异常

3、debugger

可以通过 pdb、IDE 等工具进行调试。

调试的具体方法这里不展开。

Python 中有两个内置方法在这里也很有帮助:

  • locals: 执行 locals() 之后, 返回一个字典, 包含(current scope)当前范围下的局部变量。
  • globals: 执行 globals() 之后, 返回一个字典, 包含(current scope)当前范围下的全局变量。
terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

vue:页面注入js修改input值

一般会直接这样写: let z…

1 天 ago

聊聊vue3中的defineProps

在Vue 3中,defineP…

2 周 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

2 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

3 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

4 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

1 月 ago