Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
def fun():
global s
print (s)
s="efg"
print (s)

s="abc"
fun()

#in fun() i need to check whether global s and local s are equal or not

What I have tried:

How to check which one is local and global while checkig whether they are equal
Posted
Updated 9-Feb-18 22:51pm

1 solution

Try something like this:
Python
def fun():
	global s
	s2 = s
	print("global: ", s)
	s = "efg"
	print("local: ", s, s2)
        if s == s2:
                print("true")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900