File tree 1 file changed +50
-0
lines changed
Roadmap/05 - VALOR Y REFERENCIA/python
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ ### Asignación de variables por VALOR ###
2
+
3
+ num1 = 23
4
+ num2 = 3.1416
5
+ string1 = "Hola Mario"
6
+ bool1 = True
7
+
8
+ ### Asignación de variables por REFERENCIA ###
9
+
10
+ nums1 = [10 , 100 , 30 ]
11
+ nums2 = (11 , 101 , 31 )
12
+
13
+ ### funciones con variables por valor ###
14
+ def func_valor (n ):
15
+ n -= 2
16
+ print (f"variable modificada en la funcion: { n } " )
17
+
18
+ print (f"Variable antes de la función: { num1 } " )
19
+ func_valor (num1 )
20
+ print (f"Variable despues de la función: { num1 } " )
21
+
22
+ ### funciones con variables por referencia ###
23
+
24
+ def func_referencia (n ):
25
+ for i , v in enumerate (n ):
26
+ n [i ] -= 1
27
+ print (f"variable modificada en la funcion: { n } " )
28
+
29
+ print (f"Variable antes de la función: { nums1 } " )
30
+ func_referencia (nums1 )
31
+ print (f"Variable despues de la función: { nums1 } " )
32
+
33
+ ### EXTRA ###
34
+ print ("\n ### EXTRA ###\n " )
35
+ def intercambio_val (valor1 , valor2 ):
36
+ aux = valor1
37
+ valor1 = valor2
38
+ valor2 = aux
39
+ return valor1 , valor2
40
+
41
+ var1 = 333
42
+ var2 = 666
43
+ char1 = ["hola" , "Mario" ]
44
+ char2 = ["Mario" , "Albiñana" ]
45
+
46
+ new1 , new2 = intercambio_val (var1 , var2 )
47
+ print (f"{ var1 } -> { new1 } \n { var2 } -> { new2 } " )
48
+
49
+ nc1 , nc2 = intercambio_val (char1 , char2 )
50
+ print (f"\n { char1 } -> { nc1 } \n { char2 } -> { nc2 } " )
You can’t perform that action at this time.
0 commit comments