1、id  is ==

在Python中,id是什么?id是内存地址,比如你利用id()内置函数去查询一个数据的内存地址:

name = '太白'
print(id(name))  # 1585831283968

== 是比较的两边的数值是否相等

is 是比较的两边的内存地址是否相等。 如果内存地址相等,那么这两边其实是指向同一个内存地址。

python小数据池、代码块1

可以说如果内存地址相同,那么值肯定相同,但是如果值相同,内存地址不一定相同

2、代码块

 1、官方解释:

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.
官方解释

相关文章:

  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
  • 2021-05-18
  • 2021-11-20
猜你喜欢
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2021-07-18
  • 2021-12-25
相关资源
相似解决方案