Variables

Definición de variables en Python

>>> #Variables
>>> a = 10
>>> a
10
>>> a + 10 
20
>>> nombre = "Alex Roel"
'Alex Roel'

>>> n #Variable no difinida
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    n #Variable no difinida
NameError: name 'n' is not defined
>>> n = None #Valor vacio
>>> n
>>> #Python es dinamico
>>> n = 10
>>> n
10
>>> n = 1.5
>>> n
1.5
>>> n = "numero"
>>> n
'numero'

>>> #Es Recomendable definir de pura minuscula 
>>> edad = 20
>>> edad
20
>>> Edad = 22
>>> EDAD = 25
>>> edad
20
>>> Edad
22
>>> EDAD
25
>>> #Formas de Definir las Varaibles 
>>> nombre_apellidos = "Alex Roel"
>>> nombre_apellidos
'Alex Roel'
>>> _nombre = "Roel"
>>> _nombre
'Roel'
>>> nombre1 = "Alex"
>>> nombre1
'Alex'
>>> nombre2 = "Roel"
>>> nombre2
'Roel'

>>> #Errorores en python 
>>> 2nombre = 20
  File "<stdin>", line 1   
    2nombre = 20
     ^
SyntaxError: invalid syntax
  
  
>>> mi-var = 10
  File "<stdin>", line 1
SyntaxError: cannot assign to operator
  
>>> my var = 20 
  File "<stdin>", line 1   
    my var = 20
       ^
SyntaxError: invalid syntax
  
  
>>> $dolar = 2.5 
  File "<stdin>", line 1
    $dolar = 2.5
    ^
SyntaxError: invalid syntax
  
  
>>> if = "Si"
  File "<stdin>", line 1
    if = "Si"
       ^
SyntaxError: invalid syntax
  
>>> exit()