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 776657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:29:01+00:00 2026-05-14T19:29:01+00:00

In response to another question of mine, someone suggested that I avoid long lines

  • 0

In response to another question of mine, someone suggested that I avoid long lines in the code and to use PEP-8 rules when writing Python code. One of the PEP-8 rules suggested avoiding lines which are longer than 80 characters. I changed a lot of my code to comply with this requirement without any problems. However, changing the following line in the manner shown below breaks the code. Any ideas why? Does it have to do with the fact that what follows return command has to be in a single line?

The line longer that 80 characters:

    def __str__(self):
    return "Car Type \n"+"mpg: %.1f \n" % self.mpg + "hp: %.2f \n" %(self.hp) + "pc: %i \n" %self.pc + "unit cost: $%.2f \n" %(self.cost) + "price: $%.2f "%(self.price)

The line changed by using Enter key and Spaces as necessary:

    def __str__(self):
    return "Car Type \n"+"mpg: %.1f \n" % self.mpg + 
                   "hp: %.2f \n" %(self.hp) + "pc: %i \n" %self.pc +
                   "unit cost: $%.2f \n" %(self.cost) + "price: $%.2f "%(self.price)
  • 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-14T19:29:02+00:00Added an answer on May 14, 2026 at 7:29 pm

    Python doesn’t let you end a line inside an expression like that; the simplest workaround is to end the line with a backslash.

    def __str__(self):
        return "Car Type \n"+"mpg: %.1f \n" % self.mpg + \
               "hp: %.2f \n" %(self.hp) + "pc: %i \n" %self.pc + \
               "unit cost: $%.2f \n" %(self.cost) + "price: $%.2f "%(self.price)
    

    In this case, the backslash must be the last character on the line. Essentially, it means “ignore the fact that there’s a newline here”. Or in other words, you’re escaping the newline, since it would normally be a significant break.

    You can escape an otherwise significant newline at any time with a backslash. It would be silly, but you could even do

    def foo():
      return \
       1
    

    so that foo() would return 1. If you didn’t have the backslash there, the 1 by itself would cause a syntax error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another question about Web proxy. Here is my code: IWebProxy Proxya = System.Net.WebRequest.GetSystemWebProxy(); Proxya.Credentials
Update IV / Current status: I've now confirmed trough another question that the character
So I adapted urllib2 as suggested by answers to another question : class HttpRequest(urllib2.Request):
In response to another question here on stackoverflow ( How do you select every
In response to another question I asked about regular expressions, I was told to
This goes along with another question that I have asked, I have a drop
This question is in response to another question by opensas : building a generic
No this is not another question about how to use AJAX. Why does this
This question is related to another question of mine: How to know if a
I've seen this Markov Chain gibberish detector written in response to another question on

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.