Python Python Basics All Together Now Gather Information

livia salgado
livia salgado
4,297 Points

TICKET PRICE IN CAPS

is there any reason why at the beginning we hace TICKET PRICE in capital letters? thanks!

3 Answers

TICKET_PRICE is in caps to emphasis the fact that the value isn't meant to be changed. You can still change the value, of course, and Python wouldn't even complain, but it is a message for the programmer saying, "Do not change the value of this variable!!"

In other languages, like Ruby, if a variable is in ALL CAPS, and you attempt to change the value, it would either cause an error or cause a warning. But Python is friendlier :)

Stuart Wright
Stuart Wright
41,069 Points

There is no technical reason, but it is a convention in Python to choose upper case variable names for constants (values which will not be changed at any point in our program). It makes it easier for other programmers looking at your code to know that this value is a constant.