خرید بک لینک

Vote count: -1

Why below is not working inside function but working outside?

def foo():
    common = {'abc' : 'xyz'}
    print(locals())
    locals().update(common)
    print(locals(),abc)

foo()

Error : NameError: global name 'abc' is not defined

If i run it outside function, it works

common = {'abc' : 'xyz'}
print(locals())
locals().update(common)
print(locals(),abc)

asked 4 mins ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 14 خرداد 1395 ساعت: 3:14

صفحه بندی