Python
Java
PHP
IOS
Android
Nodejs
JavaScript
Html5
Windows
Ubuntu
Linux
Python:多重分配与单独分配速度
我一直在寻求从我的代码中挤出更多的性能 最近 在浏览时这个 Python 维基页面 https wiki python org moin PythonSpeed 我发现了这个说法 多重分配比单独分配慢 例如 x y a b 比 x a y
python
performance
variableassignment
timeit
pythoninternals
python中remove方法的安全使用
我从列表继承了一个 UserList 类并实现了以下方法来删除标记为已删除的条目 def purge deleted self for element in list iter self if ele mark deleted lt 1 s
python
pythoninternals
我们能让 1 == 2 成立吗? [复制]
这个问题在这里已经有答案了 Python ints are objects封装实际数值 我们可以修改该值吗 例如设置对象的值1到2 以便1 2变成True 我们可以 但不要在家里这样做 说真的 1对象在很多地方使用 我不知道这可能会破坏什么
python
cpython
pythoninternals
为什么namedtuple模块不使用元类来创建nt类对象?
我花了一些时间调查collections namedtuple module https hg python org cpython file 3b920a778484 Lib collections init py l265几周前 该模块
python
metaclass
pythoninternals
namedtuple
为什么函数(Python)的 __code__ 是可变的
在昨天的上一个问题中 在评论中 我开始知道在 python 中 code 函数的属性是可变的 因此我可以编写如下代码 def foo print Hello def foo2 print Hello 2 foo foo code foo2
python
internals
pythoninternals
使用Python 3中的exec'ed字符串中定义的函数[重复]
这个问题在这里已经有答案了 为什么以下 python3 代码会产生错误 a def x print 42 class Test def init self exec a x t Test 此消息的结果 Traceback most rece
python
python3x
pythoninternals
asyncio 实际上是如何工作的?
这个问题是由我的另一个问题引发的 如何在cdef中等待 https stackoverflow com questions 48989065 how to await in cdef 网络上有大量关于asyncio 但它们都非常肤浅 我找不
python
python3x
pythonasyncio
pythoninternals
为什么 Python 中的函数/方法调用成本昂贵?
In 这个帖子 https web archive org web 20180919031245 https plus google com 115212051037621986145 posts HajXHPGN752 Guido van
python
profiling
functioncall
pythoninternals
python @properties 如何以及何时进行评估
这是一段代码 class TestClass def init self self a a print calling init property def b self b b print in property return b test
python
properties
pythoninternals
列表推导式是 Python 3 中“列表(生成器表达式)”的语法糖吗?
在 Python 3 中 列表理解是一个简单的语法糖 用于输入到生成器表达式中list功能 例如是下面的代码 squares x 2 for x in range 1000 实际上在后台转换成以下内容 squares list x 2 fo
推导式符号表中的这些额外符号是什么?
我在用着symtable https docs python org 3 6 library symtable html获取一段代码的符号表 奇怪的是 当使用推导式 listcomp setcomp 等 时 有一些我没有定义的额外符号 重现
python
python3x
listcomprehension
pythoninternals
为什么在Python中关闭Sqlite3的游标
使用Python时关闭游标有什么好处sqlite3模块 https docs python org 2 7 library sqlite3 html module sqlite3 或者它只是一个人工制品数据库API v2 0 https w
python
SQLite
pythoninternals
databasecursor
pythondbapi
元组 (a,b)=(b,a) 中的成员交换在内部如何工作?
In 55 a 5 In 56 b 6 In 57 a b b a In 58 a Out 58 6 In 59 b Out 59 5 a 和 b 的值交换在内部是如何工作的 它绝对不使用临时变量 Python 将右侧表达式与左侧赋值分开
python
tuples
pythoninternals
iterableunpacking
Python中str是如何实现的?
gt gt gt import sys gt gt gt sys getsizeof 40 为什么空字符串使用这么多字节 有谁知道这40个字节中存储了什么 在Python中 字符串是对象 因此值是对象本身的大小 所以这个大小总是大于字符串本
python
python27
pythoninternals
对python的LOAD_FAST/STORE_FAST感到困惑
当我写一些代码时 我发现一个有趣的事情 def test l for i in range 10 def f pass print f l append f test import dis dis dis test 输出是
python
bytecode
pythoninternals
Python 3 整数地址[重复]
这个问题在这里已经有答案了 x 300 y 300 print id x id y a 300 300 print id a 0 id a 1 在执行上面的代码时 我得到不同的地址x and y但相同的地址a 0 and a 1 谁能告诉我
python
python3x
Integer
pythoninternals
str(列表) 是如何工作的?
为什么str list 返回我们如何在控制台上看到列表 如何str list 工作 任何对 CPython 代码的引用str list gt gt gt x abc def ghi gt gt gt str x abc def ghi 要从
python
string
list
eval
pythoninternals
有人可以解释一下 staticmethod 的源代码在 python 中是如何工作的吗
首先 我了解装饰器一般是如何工作的 而且我知道 staticmethod去掉签名中的实例参数 使得 class C object staticmethod def foo print foo C foo
python
decorator
staticmethods
pythondecorators
pythoninternals
为什么元组比列表占用更少的内存空间?
A tuple在 Python 中占用更少的内存空间 gt gt gt a 1 2 3 gt gt gt a sizeof 48 whereas lists 占用更多内存空间 gt gt gt b 1 2 3 gt gt gt b size
python
python27
list
tuples
pythoninternals
为什么 Python 的 lambda 表达式中不允许赋值?
这不是重复的Python 中 lambda 表达式内的赋值 https stackoverflow com questions 6282042 assignment inside lambda expression in python 即我
python
Lambda
pythoninternals
sideeffects
1
2
3
4
5
»