如何将文本文件读入字符串变量并删除换行符?

with open ("data.txt", "r") as myfile:
    data=myfile.readlines()
LLKKKKKKKKMMMMMMMMNNNNNNNNNNNNN
GGGGGGGGGHHHHHHHHHHHHHHHHHHHHEEEEEEEE
['LLKKKKKKKKMMMMMMMMNNNNNNNNNNNNN\n', 'GGGGGGGGGHHHHHHHHHHHHHHHHHHHHEEEEEEEE']

答案

with open('data.txt', 'r') as file:
    data = file.read().replace('\n', '')
with open('data.txt', 'r') as myfile:
  data = myfile.read()
str = open('very_Important.txt', 'r').read()
with open('t.txt') as f:
  s = " ".join([x.strip() for x in f])
from pathlib import Path
txt = Path('data.txt').read_text()
txt = txt.replace('\n', '')
with open("data.txt") as myfile:
    data="".join(line.rstrip() for line in myfile)
text_as_string = open('Your_Text_File.txt', 'r').read()
text_as_string = open('Your_Text_File.txt').read()
with open("myfile.txt") as f:
    file_content = f.read().rstrip("\n")
    print file_content
with open ("data.txt", "r") as myfile:
    data = ' '.join([line.replace('\n', '') for line in myfile.readlines()])
myfile = open("data.txt","r")
data = ""
lines = myfile.readlines()
for line in lines:
    data = data + line.strip();