STRIP() | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

STRIP()

Guys I'm finding it difficult to understand the strip() method file = open("/usercode/files/books.txt", "r") books = file.readlines() print(books) if this code gets printed, you'd get a list of words with the new line code"/n", but when you print this file = open("/usercode/files/books.txt", "r") books = file.readlines() books = [x.strip() for x in books] print(books) The new line symbol gets deleted somehow. I'm confused cause i thought the strip only works when you specify the characters you want to remove in the parenthesis like this---> strip("\n").

4th Feb 2022, 4:16 PM
NWACHUKWU PRECIOUS CALEB
NWACHUKWU PRECIOUS CALEB - avatar
0 Réponse