What is the use of global variables in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is the use of global variables in python

What is the use of global variables in python

11th Jun 2020, 10:00 AM
Vincent Lim
Vincent Lim - avatar
2 Answers
+ 5
You can maintain a value throughout the code and manipulate with it in particular independent blocks of code. Think of a game, where your character has an HP parameter. It can be influenced by many different situations and events, but has to be maintained globally, so that you know whether your character is dead or not :)
11th Jun 2020, 10:03 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
12th Jun 2020, 5:22 AM
Vincent Lim
Vincent Lim - avatar