0

Can someone elaborate this code

file = open("/usercode/files/books.txt", "r") for line in file : print(line[0] + str(len(line.strip()))) file.close() Especially the line.strip part (Taken from python core module end question)

23rd Apr 2021, 8:43 AM
Faiz Shaikh
Faiz Shaikh - avatar
1 Resposta
+ 5
strip() is an inbuilt function in Python programming language that returns a copy of the string with both leading and trailing characters removed (based on the string argument passed). src: https://www.geeksforgeeks.org/python-string-strip/ [CODE] l = '@@lone@@@' print(l.strip('@')) # O/P: lone r = ' cool ' print(r.strip()) # O/P: cool
23rd Apr 2021, 8:49 AM
minirkk
minirkk - avatar