Ankky Ankky - 4 months ago 32
Python Question

Python prints text in next line

Hi I am reading a text from sample.txt which contains the value 'a'. But when I print it like this-

content = open(filepath,'r')
text = content.readlines()
print(text + ',')

Expected output -

Output obtained -


Because of this I am facing issue. Please help.


This is probably because there is \n character at the end of the line where a is found. Try using this:

print(text.strip() + ',')