for example, i have this code

def awal():
    a = 2

def akhir():
    print(a)
awal()
akhir()

well i got error that said a is not defined?
i used global, same error
use return, same error
any idea why?

If you want to use variables defined in function to be available across all functions then use a class.

def awal():
  global a
  a=2
  return a

def akhir():
  a = awal()
  print(a)

akhir()

You just miss one thing just check my code..

def awal():

  a=2
  return a

def akhir():
  a = awal()
  print(a)

akhir()

This is second code without global variable..