How to enter multi-line strings in python

Release: 2019-07-01 18:03:34
Original
9120 people have browsed it

How to enter multi-line strings in python

Enter multi-line strings in Python:

Method 1: Use triple quotes

>>> str1 = '''Le vent se lève, il faut tenter de vivre. 
起风了,唯有努力生存。
(纵有疾风起,人生不言弃。)'''
 
>>> str1
'Le vent se lève, il faut tenter de vivre. \n起风了,唯有努力生存。\n(纵有疾风起,人生不言弃。)'
 
>>> print(str1)
Le vent se lève, il faut tenter de vivre. 
起风了,唯有努力生存。
(纵有疾风起,人生不言弃。)
Copy after login

Method 2: Use backslashes

>>> str2 = 'Le vent se lève, il faut tenter de vivre. \
起风了,唯有努力生存。\
(纵有疾风起,人生不言弃。)'
 
>>> str2
'Le vent se lève, il faut tenter de vivre. 起风了,唯有努力生存。(纵有疾风起,人生不言弃。)'
Copy after login

Method 3: Use parentheses

>>> str3 = ('Le vent se lève, il faut tenter de vivre.' 
'起风了,唯有努力生存。'
'(纵有疾风起,人生不言弃。)')
 
>>> str3
'Le vent se lève, il faut tenter de vivre.起风了,唯有努力生存。(纵有疾风起,人生不言弃。)'
Copy after login

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to enter multi-line strings in python. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template