Curso de Programación en Python/CrearFunción-4
Ir a la navegación
Ir a la búsqueda
CrearFunción-4.py
1 #!/usr/bin/python3
2 #-*-coding: utf-8 -*-
3
4 a_var = 10
5 b_var = 15
6 e_var = 25
7
8 def a_func( a_var ):
9 print( "en a_func a_var = ", a_var )
10 b_var = 100 + a_var
11 d_var = 2 * a_var
12 print( "en a_func b_var = ", b_var )
13 print( "en a_func d_var = ", d_var )
14 print( "en a_func e_var = ", e_var )
15 return b_var + 10
16
17 c_var = a_func( b_var )
18
19 print( "a_var = ", a_var )
20 print( "b_var = ", b_var )
21 print( "c_var = ", c_var )
22 print( "d_var = ", d_var )
Resultado
in a_func a_var = 15 in a_func b_var = 115 in a_func d_var = 30 in a_func e_var = 25 a_var = 10 b_var = 15 c_var = 125 d_var = Traceback (most recent call last): File "C:\def2.py", line 19, in <module> print("d_var = ", d_var) NameError: name 'd_var' is not defined