the format of my .txt file looks like this:
a
abc
apple
hello
I am using this code to read them as string:
with open("wordsEn.txt") as infile:
for line in infile:
print(i)
My output is something like this where there is an additional line after each string. What went wrong there? How can I remove them? also the length of every string is not right.. where the first string 'a' 's legth is 2
a
abc
apple
hello
linealso contains the tailing new line'\n'character. By defaultprint(..)adds an additional new line. You can useprint(line,end='')to prevent that.