Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#PYTHON#8205 Back

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

		 

Click to open popup

Run Output

Sentence with all the alphabets is "The quick brown fox jumps over a lazy dog"
Sentence with all the alphabets is "The quick
brown fox jumps over a lazy dog"
[10, 20, 30, 40, 50, 60, 70, 80, 90]
Everything matches

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.