从Python中readline()函数读取的一行内容中含有换行符\n,这里讲述两种方法去掉换行符\n。
方法一是修改print()函数;
f = open("qwert.txt","r")
c = f.readline()
print(c,end="")
f.close()
方法二是使用strip()函数。
f = open("qwert.txt","r")
c = f.readline()
print(c.strip('\n'))
f.close
从Python中readline()函数读取的一行内容中含有换行符\n,这里讲述两种方法去掉换行符\n。
方法一是修改print()函数;
f = open("qwert.txt","r")
c = f.readline()
print(c,end="")
f.close()
方法二是使用strip()函数。
f = open("qwert.txt","r")
c = f.readline()
print(c.strip('\n'))
f.close