Home  >  Article  >  Backend Development  >  How to enter multi-line strings in python

How to enter multi-line strings in python

尚
Original
2019-07-01 18:03:349127browse

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. 
起风了,唯有努力生存。
(纵有疾风起,人生不言弃。)

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. 起风了,唯有努力生存。(纵有疾风起,人生不言弃。)'

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.起风了,唯有努力生存。(纵有疾风起,人生不言弃。)'

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!

Statement:
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