Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top