Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
Can anyone tell me how to declare global variables in Python?

1 Answer

0 votes
by (108k points)

For declaring the global variable, you need to create a class and in the class, you can define your global variable:

class globalvar:

    a=10 #global variable

    def fun1():

        b=1 #local variable

        c=a-b

        print(c)

If you are looking for an online course to learn Python, I recommend this Python Course by Intellipaat.

Related questions

0 votes
2 answers
0 votes
1 answer
asked Aug 5, 2019 in Python by Sammy (47.6k points)
+1 vote
2 answers
0 votes
1 answer
asked Aug 1, 2019 in Java by Aarav (11.4k points)

Browse Categories

...