A Python program is constructed from code blocks. A block is a piece of Python program text that is executed as a unit. The following are blocks: a module, a function body, and a class definition. Each command typed interactively is a block. A script file (a file given as standard input to the interpreter or specified as a command line argument to the interpreter) is a code block. A script command (a command specified on the interpreter command line with the ‘-c‘ option) is a code block. The string argument passed to the built-in functions eval() and exec() is a code block. A code block is executed in an execution frame. A frame contains some administrative information (used for debugging) and determines where and how execution continues after the code block’s execution has completed.粗略的翻译:
python步伐是由代码块构成的. ⼀个代码块的⽂本作为python步伐执⾏的单元. 代码块: ⼀个模块, ⼀个函数, ⼀个类,二、接下来我们来看一下小数据池is和 ==的区别
甚⾄每⼀个command下令都是⼀个代码块. ⼀个⽂件也是⼀ 个代码块, eval()和exec()执⾏的时间也是⼀个代码块
对于整数, Python官⽅⽂档中这么说:在python中对-5到256之间的整数会被驻留在内存中,将一定规则的字符串缓存,在使用的时间,内存中只会创建一个该数据的对象,保存小数据池中,当使用的时间直接从
The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of 1. I suspect the behaviour of Python in this case is undefined.
对于字符串:
Incomputer science, string interning is a method of storing only onecopy of each distinct string value, which must be immutable. Interning strings makes some stringprocessing tasks more time- or space-efficient at the cost of requiring moretime when the string is created or interned. The distinct values are stored ina string intern pool. –引⾃维基百科
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |