Quantcast
Channel: How to avoid using global variables? - Stack Overflow
Browsing latest articles
Browse All 4 View Live

Answer by ggorlen for How to avoid using global variables?

The term "Pythonic" doesn't apply to this topic--using globals like this is poor practice in any programming language and paradigm and isn't something specific to Python.The global keyword is the tool...

View Article



Answer by Soerendip for How to avoid using global variables?

Never write 'global'. Then you are sure you are not introducing any global variables.You could also pass the values as arguments:def secondary_function(): alfa = 12 beta = 5 if alfa > 10:...

View Article

Answer by sjc for How to avoid using global variables?

One could ask what reasons you might have to structure your code like this, but assuming you have your reasons, you could just return the values from your secondary function: def secondary_function():...

View Article

How to avoid using global variables?

I use global variables but I've read that they aren't a good practice or pythonic. I often use functions that give as a result many yes/no variables that I need to use in the main function. For...

View Article
Browsing latest articles
Browse All 4 View Live


Latest Images