Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do you make global variables in python 3?

+5 votes
asked Mar 16, 2022 by popstar403 (750 points)
I'm trying to make a global ticker, but i don't know how to make a variable global.

1 Answer

+2 votes
answered Mar 16, 2022 by Jacob Buck (240 points)
reshown Mar 16, 2022 by Jacob Buck

Hello, Global variables are variables that are simply created outside of a function. You do not need to specify anything specific. If you would like to create a global variable inside of a function you would use the "global" keyword, which then makes the variable belong to the global scope, down below is an example.


If you use the global keyword, the variable belongs to the global scope:

def myfunc():
  global x
  x = "fantastic"


print("Python is " + x)

For referencing please refer to this website as it has many great solutions and answers to your questions: 


Also feel free to contact me also.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.