Please some one explain this code to me ?? ain't get?

0 sumit bhatt · June 14, 2015
lines=cs_str.split('\\n') from this line am not able to understand the code

Post a Reply

Replies

Oldest  Newest  Rating
0 Halcyon Abraham Ramirez · June 14, 2015

lines=cs_str.split('\n')

I think you added an extra backslash.

lets break it down


cs_str.split('\n')

this means whatever string is in cs_str split it at the new line

consider this:


cs_str = """Hello I am an example of a multiline comment
I contain many lines and will soon be split
each time there is a new line"""

line = cs_str.split("\n")

print(line)

run this. The output is

['Hello I am an example of a mltiline comment', 'I contain many lines and will soon be split', 'each time there is a new line']

so now line is a list of all that has been split at cs_str

split always returns a list
  • 1

Python

106,945 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator