Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

long text as String in python

Hey I would like to declare a String in Python which is a long text (with line breaks and paragraphs). Is this possible? If I just copy-paste de text into quotations Python only recognizes the first line and I have to manually remove all the line breaks if I want the entire text. If this is possible would it still be possible if the text have quotations ("")?

like image 520
user1031431 Avatar asked Jul 17 '12 14:07

user1031431


People also ask

How do you write long text in Python?

Use triple quotes : mytext = """Some text Some more text etc... """ Note that while not commonly used, triple single quotes also work although triple-double-quotes are preferred (as long as your string doesn't contain triple-double-quotes). Phew, that's a mouthful.

How do you convert text to string in Python?

To convert an integer to string in Python, use the str() function. This function takes any data type and converts it into a string, including integers. Use the syntax print(str(INT)) to return the int as a str , or string.

How do you return a multiline string in Python?

Use """ (double quote) or ''' (single quote) for multiline string or use \ for seperating them. NOTE: """ and ''' should be used with care otherwise it may print too many spaces in between two lines.


1 Answers

Use triple quotes :

mytext = """Some text
Some more text
etc...
"""
like image 130
Kassym Dorsel Avatar answered Oct 15 '22 05:10

Kassym Dorsel