0

This code doesn't initializes the variables that I expect to be initialized.

a,b,c = [None]*3

def __init_abc():
    a="a"
    b="b"
    c="c"
    
def print_abc():
    __init_abc()
    print(a,b,c)
    
print_abc()

Output is:

None None None
Dan Nagle
  • 4,384
  • 1
  • 16
  • 28

1 Answers1

0

Within the __init_abc function you need to specify the global variables a, b, c otherwise the variables are presumed to be local to the function.

a,b,c = [None]*3

def __init_abc():
    global a,b,c
    a="a"
    b="b"
    c="c"
    
def print_abc():
    __init_abc()
    print(a,b,c)
    
print_abc()

Output:

a b c
Dan Nagle
  • 4,384
  • 1
  • 16
  • 28