I understand that in Python you don't need to "declare" variables because it is dynamic. However I was wondering what was the correct way of saying it:

  1. "Assign a variable"
  2. "Define a variable"

This is just out of curiosity, but it also would be nice to understand it for documentation purposes.

Are they the same? If they are interchangeable, What is the preferred way?

有帮助吗?

解决方案

In Python, you bind a "name" to an object.

From https://docs.python.org/2/reference/executionmodel.html:

"Names refer to objects. Names are introduced by name binding operations. Each occurrence of a name in the program text refers to the binding of that name established in the innermost function block containing the use."

Also, you may wish to see visualization like this, to make things more clear.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top