0
Пожалуйста, помогите, я с ума схожу, как убрать из подсчета символов \n? И пробелы убрать при выводе
Please help, I'm going crazy, how can I remove \ n from the character count? And remove spaces in the output file = open("/usercode/files/books.txt", "r") lines = file.readlines() for line in lines: print (line[0],(len(line))-1) file.close()
6 odpowiedzi
+ 1
To remove space between printed values use sep="". Like this:
print(line[0],len(line)-1,sep="")
If you are not sure that the last element is always '\n', you can just remove the trailing '\n' :
line=line.rstrip('\n')
print(line[0],len(line), sep="")
+ 1
Thank you!!!!! Is work!!!!
0
When you use a comma in a print statement, it's replaced by a space. Use a '+' as in:
for line in lines:
print(line[0] + (len(line) - 1))
0
This + not work
0
right, because its a number. add the string of the length of the line minus 1
- 2
Тут я хэр знает, я по Html