Jump to content

local variable vs global variable


Recommended Posts

Posted

 

 

    
print "Hello World!\n"

def f():
    global s
    print(s)
    s = "allah is good "
    print(s) 


s = "local diety is great!"
f()
print(s)

Posted
1 hour ago, RoadRomeo said:

 

 

    
print "Hello World!\n"

def f():
    global s
    print(s)
    s = "allah is good "
    print(s) 


s = "local diety is great!"
f()
print(s)

your output:

 

local diety is great!

allah is good

local diety is great!

 

Posted
1 hour ago, RoadRomeo said:

 

 

    
print "Hello World!\n"

def f():
    global s
    print(s)
    s = "allah is good "
    print(s) 


s = "local diety is great!"
f()
print(s)

Add exception too:

 

55c580571ce4190f8a45f2dc0b827a94.gif

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...