

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to wrap long lines in Python?
The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. If necessary, you can add an extra pair of parentheses around an expression, but sometimes using a backslash looks better. Make sure to indent the continued line appropriately. The preferred place to break around a binary operator is after the operator, not before it.
Example of paranthesized line break:
list( "Hello" )
This will give the output:
['H', 'e','l', 'l', 'o']
Example of back-slashed line break:
print 'This s a really long line,', \ 'but we can make it across multiple lines.'
This will give the output:
This is a really long line, but we can make it across multiple lines.
Both of these can be used, you may choose to use either depending on which looks more readable to you.
- Related Questions & Answers
- How to write long strings in Multi-lines C/C++?
- How to wrap python object in C/C++?
- How to allow long and unbreakable words to be broken and wrap to the next line in JavaScript?
- How long does it take to learn Python?
- How to convert Long array list to long array in Java?
- How to match pattern over multiple lines in Python?
- How to eliminate repeated lines in a python function?
- Program to find how many lines intersect in Python
- How to create a long multi-line string in Python?
- Convert long primitive to Long object in Java
- Lines and Indentation in Python
- How to write multiple lines in text file using Python?
- How to delete lines from a Python tkinter canvas?
- How to word-wrap text in Tkinter Text?
- How do I wrap a string in a file in Python?
Advertisements