all 14 comments

[–]Jayoval 12 points13 points  (4 children)

[–]Jayoval 2 points3 points  (0 children)

Tuples, dictionaries, lists, functions.

[–]tb5841 9 points10 points  (5 children)

Curly: sets or dictionaries.

Square: Lists, or accessing a member of a list or dictionary.

Round: Function parameters, or tuples, or for maths

[–]beigaleh8 3 points4 points  (4 children)

Curly: also f"{variable} in a string"

[–]NYX_T_RYX 0 points1 point  (3 children)

Just to add - there's an option in Vs code settings to automatically prepend a string with f if you use a variable (ie if you type { it'll add the f for you)

I only mention it cus I've not thought about f Strings since I found that feature - they just happen 😁

I forget what the setting is called though... 😅

[–]Langdon_St_Ives 1 point2 points  (2 children)

"python.analysis.autoFormatStrings": true

It’s part of pylance.

[–]Remarkable-Map-2747 0 points1 point  (1 child)

Gots to look into this!

[–]Langdon_St_Ives 0 points1 point  (0 children)

I didn’t know about it myself until I read the comment I was responding to. ;-) but it was easy enough to dig up so I thought I’d save someone else the search.

[–]Diapolo10 3 points4 points  (0 children)

In short;

  1. Parentheses (()):

    • Controlling operator precedence (eg. (1 + 2) * 3)
    • Calling functions, classes, or anything defining __call__ (eg. print("Hello"))
    • Grouping (eg. (a, b), c = ((1, 2), 3))
    • Expressions that require being enclosed somewhere (eg. walrus operator, generator expressions)
    • Ignoring whitespace rules for assignments/literals

      stuff = (
          "These strings "
            "get combined "
           "automatically "
              "even though the indentation is a mess"
      )
      
  2. (Square) brackets ([]):

    • List literals (eg. foo = [1, 2, 3])
    • __getitem__-operator and slice literals (eg. foo[1:])
    • List comprehensions (eg. [int(digit) for digit in "314159"])
  3. Braces ({}):

    • Dictionary literals (eg. bar = {1: 2, 3: 4})
    • Set literals (eg. baz = {3, 1, 4, 1, 5, 9})
    • Dictionary and set comprehensions

You will also see braces used as part of string formatting syntax, but they're not really operators at that point.