-2

From this django answer in SO, I found 3 variables "JAN", "FEB" and "MAR" in the class "Month" extending "models.TextChoices" as shown below:

# "models.py"

from django.db import models

class MyModel(models.Model):
    class Month(models.TextChoices):
        JAN = "1", "JANUARY"  # Here
        FEB = "2", "FEBRUARY" # Here
        MAR = "3", "MAR"      # Here
        # (...)

    month = models.CharField(
        max_length=2,
        choices=Month.choices,
        default=Month.JAN
    )

And multiple values are assigned to each variable without brackets "[]" which creates List or parentheses "()" which creates Tuple as shown below:

JAN = "1", "JANUARY"
FEB = "2", "FEBRUARY"
MAR = "3", "MAR"

Now, can multiple values be assigned to one variable without brackets "[]" or parentheses "()" in Python?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129

1 Answers1

-1

Yes, multiple values can be assigned to one variable without brackets "[]" or parentheses "()".

And these below are actually Tuple:

JAN = "1", "JANUARY"
FEB = "2", "FEBRUARY"
MAR = "3", "MAR"

So, in Python, you can create Tuple without parentheses "()".

For example, these below are Tuple:

fruits = "Apple", "Orange", "Banana"
fruits = "Apple",

In addition, this below without a trailing comma is not Tuple. This below is String type:

fruits = "Apple"
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129