I recently bought a book called "Black Hat Python". However, I found that some variables are only made out of uppercase and the book was using it like a global variable. Is there any feature in python that globalize variable by making a variable with only upper cases?
2 Answers
As of now, there is no such method. Rather you could define a global variable using the global keyword.
Here is an example:
def myfunction():
global s
s += ' Hello World'
print(s)
s = "I love python"
print(s)
# Global Scope
s = "Python is great!"
f()
print(s)
You can refer to this link for reference - link
Comments
There is no any difference for python how you set your variable. Uppercase may be used just for visual explanation.
You can read more about it via link:
MAXwhen I need to store a max value not to conflict with the builtinmax, which doesn't make it a global nor immutable variable ;)