How do I specify new lines on Python when writing on files

0 votes
In comparison to Java (in a string), you would do something like "First Line\r\nSecond Line".

So how would you do that in Python, for purposes of writing multiple lines to a regular file?
Feb 14, 2022 in Python by Dev
• 6,000 points
250 views

1 answer to this question.

0 votes

In Python \n is used for new lines,  it is newliine character.

print('This is the first line \n notice the space\nthe next line starts')

Output

This is the first line 
 notice the space
the next line starts

answered Feb 14, 2022 by Nandini
• 5,480 points

Related Questions In Python

0 votes
1 answer

How do I specify new lines on Python, when writing on files?

It is up to you to decide ...READ MORE

answered Feb 14, 2022 in Python by CoolCoder
• 4,400 points
381 views
–1 vote
2 answers
0 votes
1 answer

When I create and remove files rapidly on windows using python I get WindowsError (Error 5)

Here's the short answer: disable any antivirus or ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
1,642 views
0 votes
1 answer

How can I rename files on the fly using Python?

You could simply use a wrapper object ...READ MORE

answered Sep 7, 2018 in Python by aryya
• 7,450 points
578 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
0 votes
1 answer

How can I add new keys to a dictionary in Python?

Yes, it is possible to add new ...READ MORE

answered Feb 9, 2022 in Python by Nandini
• 5,480 points
316 views
0 votes
1 answer

How can I count the occurrences of a list item?

For Counting the occurrences there are many ...READ MORE

answered Feb 7, 2022 in Python by Nandini
• 5,480 points
266 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP