Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:14:39+00:00 2026-05-26T16:14:39+00:00

I have some code like this. Should the break occur before the periods or

  • 0

I have some code like this. Should the break occur before the periods or after?

# before
my_var = somethinglikethis.where(we=do_things).where(we=domore).where(we=everdomore)

# this way
my_var = somethinglikethis.where(we=do_things) \
                          .where(we=domore) \
                          .where(we=everdomore)

# or this way
my_var = somethinglikethis.where(we=do_things). \
                           where(we=domore). \
                           where(we=everdomore)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:14:40+00:00Added an answer on May 26, 2026 at 4:14 pm

    PEP 8 recommends using parenthesis so that you don’t need \, and gently suggests breaking before binary operators instead of after them. Thus, the preferred way of formatting you code is like this:

    my_var = (somethinglikethis
              .where(we=do_things)
              .where(we=domore)
              .where(we=everdomore))
    

    The two relevant passages are this one from the Maximum Line Length section:

    The preferred way of wrapping long lines is by using Python’s implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

    … and the entire Should a line break before or after a binary operator? section:

    Should a line break before or after a binary operator?

    For decades the recommended style was to break after binary operators.
    But this can hurt readability in two ways: the operators tend to get
    scattered across different columns on the screen, and each operator is
    moved away from its operand and onto the previous line. Here, the eye
    has to do extra work to tell which items are added and which are
    subtracted:

    # No: operators sit far away from their operands
    income = (gross_wages +
              taxable_interest +
              (dividends - qualified_dividends) -
              ira_deduction -
              student_loan_interest)
    

    To solve this readability problem, mathematicians and their publishers
    follow the opposite convention. Donald Knuth explains the traditional
    rule in his Computers and Typesetting series: “Although formulas
    within a paragraph always break after binary operations and relations,
    displayed formulas always break before binary operations”

    Following the tradition from mathematics usually results in more
    readable code:

    # Yes: easy to match operators with operands
    income = (gross_wages
              + taxable_interest
              + (dividends - qualified_dividends)
              - ira_deduction
              - student_loan_interest)
    

    In Python code, it is permissible to break before or after a binary
    operator, as long as the convention is consistent locally. For new
    code Knuth’s style is suggested.

    Note that, as indicated in the quote above, PEP 8 used to give the opposite advice about where to break around an operator, quoted below for posterity:

    The preferred way of wrapping long lines is by using Python’s implied line
    continuation inside parentheses, brackets and braces. Long lines can be
    broken over multiple lines by wrapping expressions in parentheses. These
    should be used in preference to using a backslash for line continuation.
    Make sure to indent the continued line appropriately. The preferred place
    to break around a binary operator is after the operator, not before it.
    Some examples:

    class Rectangle(Blob):
    
        def __init__(self, width, height,
                     color='black', emphasis=None, highlight=0):
            if (width == 0 and height == 0 and
                color == 'red' and emphasis == 'strong' or
                highlight > 100):
                raise ValueError("sorry, you lose")
            if width == 0 and height == 0 and (color == 'red' or
                                               emphasis is None):
                raise ValueError("I don't think so -- values are %s, %s" %
                                 (width, height))
            Blob.__init__(self, width, height,
                          color, emphasis, highlight)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code like this in a winforms app I was writing to
I have some code like this: If key.Equals(search, StringComparison.OrdinalIgnoreCase) Then DoSomething() End If I
I have some code like this: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save([Bind(Prefix=)]Person person) { String s
I have some code like this: doDatabaseFetch { ... @synchronized(self) { ... } }
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
Let's say I have some code like this if(isset($_GET['foo'])) //do something if(isset($_GET['bar'])) //do something
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
This is a really basic question but... I have some code like this var
In PHP, say that you have some code like this: $infrastructure = mt_rand(0,100); if
I have some code that looks like this: someFunc(value) { switch(value){ case 1: case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.