0

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
  • 4
    This is just a convention, usually for constants (a fixed value not modified by the code), not always used . For example I sometimes use MAX when I need to store a max value not to conflict with the builtin max, which doesn't make it a global nor immutable variable ;) Commented Jun 4, 2022 at 8:41
  • Related: stackoverflow.com/questions/7078731/… Commented Jun 4, 2022 at 8:50

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

-1

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:

-> Python variables

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.