mindly.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mindly.Social is an English speaking, friendly Mastodon instance created for people who want to use their brains and their hearts to make social networking more social. 🧠💖

Administered by:

Server stats:

1.1K
active users

Just learning #Python... it doesn't have constants? Really? And you're supposed to simulate them by using a naming convention? You're kidding me, right?

@cenbe

Not sure exactly what you're getting at; there are various approaches. If you want , use the enum module/base class, and you can have constants of any flavour you like, protected from assignment. It's in the standard library and highly recommended.

If, on the other hand, you're trying to protect the user from themselves, you can create an that represents a but which resists changing value - but you can't prevent the user assigning to a name.

[...]

C.

@cenbe

i.e. the user can do `x = your_immutable_object`, and the user can't change the object - but they can assign a different object to the name `x`.

That `x` belongs to them; it's part of their , so that seems reasonable.

What is the problem you're trying to solve, and what exactly do you mean by "constant" in regards to that problem?