gpt4 book ai didi

python - 如何知道在python中为不同的属性分配相同的值哪个更有优势

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:26 25 4
gpt4 key购买 nike

在 python 中,两者之间哪个更快,更有优势

a = b = c = d = 1

a = 1
b = 1
c = 1
d = 1

最佳答案

简单地运行一个测试:

>>> import timeit
>>> min(timeit.repeat('a = b = c = d = 1', number=10000000))
0.4885740280151367
>>> min(timeit.repeat('a = 1; b = 1; c = 1; d = 1', number=10000000))
0.6283371448516846

另请注意:

>>> min(timeit.repeat('a, b, c, d = 1, 1, 1, 1', number=10000000))
0.4040501117706299

关于python - 如何知道在python中为不同的属性分配相同的值哪个更有优势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40122713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com