Python in VS Code Not Allowing Implicit Line Continuation?

118 Views Asked by At

I was reading that Python allows for implicit line continuation as long as you are in brackets or parentheses; however in VS Code it doesn't seem to allow this behavior for me, and I'm required to use the explicit forward slash line continuation.

plt.title("Monte Carlo Dice Game [" + str(num_simulations) + "
      simulations]")

Pylance error triggered: VS Code Error

Is there some sort of setting which I need to enable to allow implicit line continuation?

Tried using a return/linebreak within the parentheses of a function call, expecting no errors to pop up within VS Code, but an error occurred.

2

There are 2 best solutions below

2
hypnoticbanana On BEST ANSWER

Per Barmar:

You can have line breaks in argument lists, but you can't have them inside strings unless you use triple quotes. – Barmar 3 hours ago

Not sure where this is documented officially but it seems to be the best answer.

0
Diego Torres Milano On

If you move the quote to the next line it will work

... str(whatever) +
    "simulations]")

you can also do like

... str(whatever)
    + "simulations]")