How to make paragraphs readable within python code

ghonke

I often have to present paragraphs of text to users. I'm ok with what I know about presenting the text to the user (usually using \n or text wrapping to make it pleasing on the user side) but is there a way to have carriage returns in my actual code without \n

a = "this is a really long line of text that i need to show to the user. this is a really long line of text that i need to show to the user. this is a really long line of text that i need to show to the user. this is a really long line of text that i need to show to the user."

b = "this is a really long line of text that i need to show to the user.\n
this is a really long line of text that i need to show to the user.\n
this is a really long line of text that i need to show to the user.\n"

So my goal is to break 'a' into aesthetically pleasing chunks in my code but still use wordwrap for displaying the text to the user. The only way I know to do that is shown in 'b' but that does not work with word wrapping

Roger Fan

So you want it readable in your actual code? Python will implicitly concatenate adjacent strings in code. To get it to work across lines you can use the line continuation character \, or, preferably, wrap it in parentheses.

a = ("This is a really long\n"
     "line of text that I\n"
     "need to show to the user.")

print(a)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to make this code more functional and readable?

From Dev

How to optimize and make the code more readable

From Dev

How to make HTML code more readable?

From Dev

How can I make my code more readable and DRYer when working with XML namespaces in Python?

From Dev

How to make vim code folding colors more readable

From Dev

How to make non-English letters readable in python?

From Dev

Yii - how to make url as readable?

From Java

How to add paragraphs to list in Python

From Dev

How can I make my JavaScript code un-readable in the developer console?

From Dev

Python: how to make this code simpler?

From Dev

How to make readable alias of a file descriptor

From Dev

How to make numbers 'human readable' in MySQL

From Dev

How can I make text in meld readable?

From Dev

How can I make text in meld readable?

From Dev

How to make a 2002 ISO image readable?

From Dev

how make pysmp oids respone readable for human

From Dev

How to convert code to more readable form in R

From Dev

How to split an image into clean paragraphs in Python/OpenCV?

From Java

How to execute Python code from within Visual Studio Code

From Dev

Logic within python and Tkinter: how to make a window run endlessly

From Dev

How to make emacs automatically indent Python code?

From Dev

How to make my python code more effective?

From Dev

how to make this code on python run faster?

From Dev

How to make this Block of python code short and efficient

From Dev

How to make this code work in python 2

From Dev

how to make this code on python run faster?

From Dev

How to make a python source code edit it self

From Dev

How to check if a module is installed in Python and, if not, install it within the code?

From Dev

How to take BigDecimal value in database and make it human readable in view

Related Related

  1. 1

    how to make this code more functional and readable?

  2. 2

    How to optimize and make the code more readable

  3. 3

    How to make HTML code more readable?

  4. 4

    How can I make my code more readable and DRYer when working with XML namespaces in Python?

  5. 5

    How to make vim code folding colors more readable

  6. 6

    How to make non-English letters readable in python?

  7. 7

    Yii - how to make url as readable?

  8. 8

    How to add paragraphs to list in Python

  9. 9

    How can I make my JavaScript code un-readable in the developer console?

  10. 10

    Python: how to make this code simpler?

  11. 11

    How to make readable alias of a file descriptor

  12. 12

    How to make numbers 'human readable' in MySQL

  13. 13

    How can I make text in meld readable?

  14. 14

    How can I make text in meld readable?

  15. 15

    How to make a 2002 ISO image readable?

  16. 16

    how make pysmp oids respone readable for human

  17. 17

    How to convert code to more readable form in R

  18. 18

    How to split an image into clean paragraphs in Python/OpenCV?

  19. 19

    How to execute Python code from within Visual Studio Code

  20. 20

    Logic within python and Tkinter: how to make a window run endlessly

  21. 21

    How to make emacs automatically indent Python code?

  22. 22

    How to make my python code more effective?

  23. 23

    how to make this code on python run faster?

  24. 24

    How to make this Block of python code short and efficient

  25. 25

    How to make this code work in python 2

  26. 26

    how to make this code on python run faster?

  27. 27

    How to make a python source code edit it self

  28. 28

    How to check if a module is installed in Python and, if not, install it within the code?

  29. 29

    How to take BigDecimal value in database and make it human readable in view

HotTag

Archive