Explains briefly how to use a namespace
try from the python prompt
import this
code
#!/usr/bin/env python
func_demo.py
basic function
scope of variable
how import module
namespace
the ...
def addme(val1,val2):
z = val1 + val2
this ok - local scope
z is only available in the function
print("In the function",z)
return z
run only if from the command line
if _name_ == "__main__":
x = int(input("Enter a value for x "))
y = int(input("Enter a value for y "))
total=addme(x,y)
print(total)
else:
... # ... is how a non-op works in python
#Done.
---------------------------------------------------------------
#!/usr/bin/env python
func_demo_in.py
basic function
how import module
namespaces
import this
you have two options here ...
from func_demo import addme
or
#import func_demo
a = int(input("Enter a value for a "))
b = int(input("Enter a value for b "))
total=addme(a,b)
#total=func_demo.addme(a,b)
print(total)#!/usr/bin/env python3
func_demo_in.py
basic function
how import module
namespaces
import this
from func_demo import addme
#import func_demo
a = int(input("Enter a value for a "))
b = int(input("Enter a value for b "))
total=addme(a,b)
print(total)
#Done.
En esta página del sitio puede ver el video en línea How namespaces work in Python de Duración hora minuto segunda en buena calidad , que subió el usuario d p 02 noviembre 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 33 veces y le gustó 0 a los espectadores. Disfruta viendo!