Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

Is there a way to declare a constant in Python? In Java we can create constant values in this manner:

public static final String CONST_NAME = "Name";

What is the equivalent of the above Java constant declaration in Python?

1 Answer

0 votes
by (106k points)

If you are in a class, the equivalent would be:

class Foo(object): 

CONST_NAME = "Name"

if not, it is just

CONST_NAME = "Name"

Related questions

0 votes
1 answer
asked Jan 18, 2020 in Python by Rajesh Malhotra (19.9k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...