Python summary: variables

A variable is a name that refers to an object (a data) in memory.

>>> var1 = 'Hello'
>>> var1
>>> var2 = 5 + 5
>>> var2

The single-equal character (=) assigns the value on the right to a variable on the left.

And the reference can be changed:

>>> var = 1
>>> var
>>> var = 2
>>> var

Even referer to a data which is refered by another variable:

Te echo una mano con el esperanto? Agéndame una videollamada de 15 minutos aquí y vemos cómo puedo ayudarte.
>>> var1 = 'Hello'
>>> var2 = var1
>>> var2

But in any case, the ones must be created at the moment it is assigned to a data:

>>> wellvar = 'Hello'
>>> badvar
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'new_var2' is not defined

And the possible characters for a variable name are:

  • It can just start with alphabetic character.
  • It can contain underscore character (_) and any alphabetic character.


More information:

Sé el primero en comentar

Deja un comentario