python rows to read the file, remove the end of each row newline "\ n"

```python

for line in file.readlines():

    line=line.strip('\n')

```

strip function prototype

Disclaimer: s a string, rm is a sequence of characters to be deleted delete only the beginning or end of a character or string. You can not delete the middle of the character or string.

s.strip (rm) to delete the beginning of the string s, at the end, located in the sequence of characters to delete rm

s.lstrip (rm) to delete the beginning of the string s, rm deleted sequence character located

s.rstrip (rm) deleted at the end of the string s, rm deleted sequence character located

note:

1. When rm is empty, delete the default whitespace (including '\ n', '\ r', '\ t', '')

E.g:

 

2. Here is the sequence rm delete characters on the long side (beginning or end) in the deletion sequence, it is deleted.

E.g:


Reference: https: //blog.csdn.net/sunny_happy08/article/details/82784446

Guess you like

Origin www.cnblogs.com/flyupwards/p/11808726.html