handling long lines
Sometimes programmers face a challenge of writing long strings, long instructions etc. Python provides a neat solution in an explicit way using \ followed by newline or in some cases implicitly like in lists.
Source Code
|
|
Run Output
Notes
- Backslash (\) followed by hard pressed newline immediately following it works like an escape sequence only. It joins two physical lines as one logical line.
- Triple quote (”’) is a technique used in python to put multiline comments or for multiline string literals when given inside print or as variable assignments.
- Collections in python like list, tuple, set as may be very long by nature so python supports writing long lines without any \ for these types of items. This is called implicitly defined long line.
Created: 11-Apr-2026 20:24 | Updated: 19-Sep-2026 20:03|
