简体   繁体   中英

Python-How to create spaces between paragraphs?

I am a beginner in Python programming. When I write my code, it gets really lengthy because I keep using a print('') under paragraphs to create space. So far my programming is with making simple tests for my sister who is a teacher for the upcoming school year. Is there a cleaner, shorter way to make spaces?

Example:

print('What is the answer for this question?')
print('')
print('')
print('answer')

New-lines can be added using the escaped character \\n . For example:

print('What is the answer for this question?\n\nanswer')

is equivalent in output to your example code.

Use \\n to insert new lines :

print('What is the answer for this question?\n\n')
print('answer')

If you do not want to print a new line, you can use this :

print('What is the answer for this question? ',end='')

You can use the \\n command in a print statement to create an "enter" block I guess.

Input:

print("This is how you can\nmake breaks!")

Output:

This is how you can
make breaks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM