错误 那么如何缓存字符串文字?某处有解释吗? 它是一些怪异的伏都教,我应该假设一个字符串文字 将始终生成一个新对象? 谢谢, Farshid When I pass an empty string to a function is a new string object createdor does python use some global pre-created object? I know python doesthis with integer objects under a certain value. For instance, in thefollowing code is a new string object created for each function call?func(0,'''')func(1,'''')func(2,'''')func(3,'''')I tried the following commands in the interactive shell:TrueThis leads me to believe that python does reuse existing strings, butonce the variables are removed, does the item still exist in the cache?-Farshid 解决方案Either; see the same reference page.----BryanIt takes far too little evidence to induce belief:regardsSteve--Steve Holden +44 150 684 7255 +1 800 494 3119Holden Web LLC www.holdenweb.comPyCon TX 2006 www.python.org/pycon/TrueHowever, the following commands add to my confusion: a = ''wtf?'' b = ''wtf?'' a is bFalseSo how are string literals cached? Is there an explanation somewhere? Isit some freaky voodoo, and I should just assume that a string literalwill always generate a new object?Thanks,Farshid 这篇关于是否空字符串缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-25 07:26